@tokenoftrust/storefront-runner 6.16.0 → 6.17.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.17.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
|
|
6
6
|
"packageManager": "pnpm@11.9.0",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"./responsive-renditions": "./src/responsive-renditions.ts",
|
|
33
33
|
"./svg-sanitize": "./src/svg-sanitize.ts",
|
|
34
34
|
"./incremental-sha256": "./src/incremental-sha256.ts",
|
|
35
|
+
"./catalog-scale": "./src/catalog-scale.mjs",
|
|
35
36
|
"./image-limits": "./src/image-limits.mjs",
|
|
36
37
|
"./tenant-record-merge": "./src/tenant-record-merge.mjs",
|
|
37
38
|
"./image-release-gate": "./src/image-release-gate.ts",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface CatalogSize {
|
|
2
|
+
readonly products: number;
|
|
3
|
+
readonly bytes: number;
|
|
4
|
+
}
|
|
5
|
+
export type CatalogScaleLevel = "ok" | "warn" | "d1-required";
|
|
6
|
+
|
|
7
|
+
export declare const CATALOG_SCALE_WARN: Readonly<CatalogSize>;
|
|
8
|
+
export declare const CATALOG_SCALE_D1_REQUIRED: Readonly<CatalogSize>;
|
|
9
|
+
export declare function catalogScaleLevel(size: CatalogSize): CatalogScaleLevel;
|
|
10
|
+
export declare function catalogScaleFinding(
|
|
11
|
+
size: CatalogSize,
|
|
12
|
+
): { level: "warn" | "d1-required"; message: string } | null;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Catalog scale thresholds: the one place the platform says how large a store's own
|
|
3
|
+
* `content/catalog/` may grow before each serving path stops being safe (ADR 0033).
|
|
4
|
+
*
|
|
5
|
+
* Two measures, because either can be the one that bites:
|
|
6
|
+
* - products: the count of `catalog/products/*.json` files;
|
|
7
|
+
* - bytes: the raw size of every file under `catalog/`.
|
|
8
|
+
*
|
|
9
|
+
* Evidence (synthetic Giant-shaped tenants, measured 2026-11-16 by
|
|
10
|
+
* `apps/storefront/src/lib/catalog/tot/catalogScale.test.ts`):
|
|
11
|
+
* - the listing projection parses in ~150 ms and ~47 MB of heap at 10,000 products;
|
|
12
|
+
* - reading the files one by one costs ~55 MB of heap at 5,000 products and ~111 MB at
|
|
13
|
+
* 10,000 against the Worker's 128 MB;
|
|
14
|
+
* - a store of 3,571 files / 42 MB failed to render in the materializer's wrangler-dev
|
|
15
|
+
* Worker (fb-1794371798042-4rqyh4), which is why bytes are a line of their own.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** A catalog at or past either line gets a non-blocking finding naming the next line. */
|
|
19
|
+
export const CATALOG_SCALE_WARN = Object.freeze({ products: 3000, bytes: 25_000_000 });
|
|
20
|
+
|
|
21
|
+
/** A catalog at or past either line must declare `catalog.serving: "d1"` to be materialized. */
|
|
22
|
+
export const CATALOG_SCALE_D1_REQUIRED = Object.freeze({ products: 5000, bytes: 40_000_000 });
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {{ products: number, bytes: number }} size
|
|
26
|
+
* @returns {"ok" | "warn" | "d1-required"}
|
|
27
|
+
*/
|
|
28
|
+
export function catalogScaleLevel({ products, bytes }) {
|
|
29
|
+
if (products >= CATALOG_SCALE_D1_REQUIRED.products || bytes >= CATALOG_SCALE_D1_REQUIRED.bytes) return "d1-required";
|
|
30
|
+
if (products >= CATALOG_SCALE_WARN.products || bytes >= CATALOG_SCALE_WARN.bytes) return "warn";
|
|
31
|
+
return "ok";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const mb = (bytes) => `${(bytes / 1_000_000).toFixed(1)} MB`;
|
|
35
|
+
|
|
36
|
+
const REMEDY =
|
|
37
|
+
"ask Token of Trust to serve this catalog from the D1 projection (`catalog.serving` is a platform " +
|
|
38
|
+
"setting, not a .tot/config.json key; public and static renders never read D1, ADR 0013), " +
|
|
39
|
+
"or split the catalog";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The finding text for a catalog at `warn` or `d1-required`, or null when it is `ok`. Names the
|
|
43
|
+
* count, the size, the next line and the remedy, and says what each CDN does at the line.
|
|
44
|
+
*
|
|
45
|
+
* @param {{ products: number, bytes: number }} size
|
|
46
|
+
* @returns {{ level: "warn" | "d1-required", message: string } | null}
|
|
47
|
+
*/
|
|
48
|
+
export function catalogScaleFinding(size) {
|
|
49
|
+
const level = catalogScaleLevel(size);
|
|
50
|
+
if (level === "ok") return null;
|
|
51
|
+
const have = `${size.products} products, ${mb(size.bytes)} of catalog files`;
|
|
52
|
+
const cdns =
|
|
53
|
+
"Cloudflare preview and publication read the catalog inside the Worker's 128 MB isolate; " +
|
|
54
|
+
"CloudFront static publication renders on a build machine, whose preview Worker bundles the catalog.";
|
|
55
|
+
if (level === "warn") {
|
|
56
|
+
return {
|
|
57
|
+
level,
|
|
58
|
+
message:
|
|
59
|
+
`catalog is ${have}; past ${CATALOG_SCALE_D1_REQUIRED.products} products or ` +
|
|
60
|
+
`${mb(CATALOG_SCALE_D1_REQUIRED.bytes)} a file-served catalog may not render. ` +
|
|
61
|
+
`${cdns} To stay ahead of it: ${REMEDY}.`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
level,
|
|
66
|
+
message:
|
|
67
|
+
`catalog is ${have}, past the ${CATALOG_SCALE_D1_REQUIRED.products}-product / ` +
|
|
68
|
+
`${mb(CATALOG_SCALE_D1_REQUIRED.bytes)} line for file-served catalogs. ${cdns} Fix: ${REMEDY}.`,
|
|
69
|
+
};
|
|
70
|
+
}
|