@tokenoftrust/storefront-runner 3.3.4 → 3.3.5
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": "3.3.
|
|
3
|
+
"version": "3.3.5",
|
|
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",
|
|
@@ -1,13 +1,92 @@
|
|
|
1
|
+
// Renders packages/public-runtime/schemas/managed-analytics/v1/*.schema.json from
|
|
2
|
+
// MANAGED_ANALYTICS_API_V1_JSON_SCHEMAS. The output is a declared derived mirror
|
|
3
|
+
// (.tot/derived-mirror-steps.json), re-derived on the umbrella tip.
|
|
4
|
+
//
|
|
5
|
+
// (no flag) write every schema file
|
|
6
|
+
// --check refuse a stale, missing or orphaned file. Inside a fold gate (TOT_FOLD_GATE=1) a
|
|
7
|
+
// stale or missing file passes with a STALE line, since the tip re-derives it; an
|
|
8
|
+
// orphan still refuses, because no derivation deletes a file.
|
|
9
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
1
10
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { MANAGED_ANALYTICS_API_V1_JSON_SCHEMAS } from "../src/integration/managed-analytics-api-v1.schemas.ts";
|
|
11
|
+
import { dirname, relative, resolve } from "node:path";
|
|
12
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
13
|
|
|
6
14
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
const
|
|
8
|
-
|
|
15
|
+
const repoRoot = resolve(here, "../../..");
|
|
16
|
+
export const OUTPUT_DIR = relative(repoRoot, resolve(here, "../schemas/managed-analytics/v1"));
|
|
9
17
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Every schema file, as repo-relative path -> text.
|
|
20
|
+
* @returns {Promise<Map<string, string>>}
|
|
21
|
+
*/
|
|
22
|
+
export async function renderManagedAnalyticsSchemas() {
|
|
23
|
+
const { MANAGED_ANALYTICS_API_V1_JSON_SCHEMAS } = await import("../src/integration/managed-analytics-api-v1.schemas.ts");
|
|
24
|
+
const files = new Map();
|
|
25
|
+
for (const schema of Object.values(MANAGED_ANALYTICS_API_V1_JSON_SCHEMAS)) {
|
|
26
|
+
const name = new URL(schema.$id).pathname.split("/").at(-1);
|
|
27
|
+
files.set(`${OUTPUT_DIR}/${name}`, `${JSON.stringify(schema, null, 2)}\n`);
|
|
28
|
+
}
|
|
29
|
+
return files;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The committed files under `root` against a fresh render: `stale` differ or are missing, `orphans`
|
|
34
|
+
* sit in the output directory with no schema rendering them.
|
|
35
|
+
* @param {string} [root]
|
|
36
|
+
*/
|
|
37
|
+
export async function findSchemaDrift(root = repoRoot) {
|
|
38
|
+
const files = await renderManagedAnalyticsSchemas();
|
|
39
|
+
/** @param {string} path */
|
|
40
|
+
const committed = (path) => {
|
|
41
|
+
try {
|
|
42
|
+
return readFileSync(resolve(root, path), "utf8");
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
let present = [];
|
|
48
|
+
try {
|
|
49
|
+
present = readdirSync(resolve(root, OUTPUT_DIR));
|
|
50
|
+
} catch {
|
|
51
|
+
present = [];
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
files,
|
|
55
|
+
stale: [...files].filter(([path, text]) => committed(path) !== text).map(([path]) => path),
|
|
56
|
+
orphans: present.map((name) => `${OUTPUT_DIR}/${name}`).filter((path) => !files.has(path)),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The `--check` verdict. A fold gate tolerates stale files, which the tip re-derives; an orphan is
|
|
62
|
+
* always red, since no derivation deletes a file.
|
|
63
|
+
* @param {{ count: number, stale: string[], orphans: string[], foldGate: boolean }} drift
|
|
64
|
+
* @returns {{ ok: boolean, lines: string[] }}
|
|
65
|
+
*/
|
|
66
|
+
export function schemaCheckVerdict({ count, stale, orphans, foldGate }) {
|
|
67
|
+
const lines = [
|
|
68
|
+
...orphans.map((path) => `managed-analytics-schemas-orphan: ${path} is not rendered by any schema; delete it`),
|
|
69
|
+
...stale.map((path) => `${foldGate ? "STALE" : "managed-analytics-schemas-stale"}: ${path}`),
|
|
70
|
+
];
|
|
71
|
+
const ok = orphans.length === 0 && (stale.length === 0 || foldGate);
|
|
72
|
+
if (!ok && stale.length > 0) lines.push(`re-derive: node ${relative(repoRoot, fileURLToPath(import.meta.url))}`);
|
|
73
|
+
if (ok) lines.push(`${count} managed analytics v1 schemas are ${stale.length > 0 ? "stale; the tip re-derives them" : "current"}`);
|
|
74
|
+
return { ok, lines };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function check() {
|
|
78
|
+
const { files, stale, orphans } = await findSchemaDrift();
|
|
79
|
+
const verdict = schemaCheckVerdict({ count: files.size, stale, orphans, foldGate: process.env.TOT_FOLD_GATE === "1" });
|
|
80
|
+
for (const line of verdict.lines) (verdict.ok ? console.log : console.error)(line);
|
|
81
|
+
if (!verdict.ok) process.exitCode = 1;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function write() {
|
|
85
|
+
const files = await renderManagedAnalyticsSchemas();
|
|
86
|
+
await mkdir(resolve(repoRoot, OUTPUT_DIR), { recursive: true });
|
|
87
|
+
for (const [path, text] of files) await writeFile(resolve(repoRoot, path), text, "utf8");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
91
|
+
await (process.argv.includes("--check") ? check() : write());
|
|
13
92
|
}
|