@gusto/baerly-storage 0.3.0 → 0.4.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/README.md +157 -92
- package/dist/API.md +64 -32
- package/dist/CHANGELOG.md +301 -5
- package/dist/RECIPES.md +125 -0
- package/dist/THIRD-PARTY-LICENSES.txt +22 -96
- package/dist/{app-config-BIzyAKzy.d.ts → app-config-DyiFK3_k.d.ts} +43 -11
- package/dist/app-config.d.ts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +13 -13
- package/dist/auth.js.map +1 -1
- package/dist/aws4fetch.esm-p7eEzLCs.js +1702 -0
- package/dist/aws4fetch.esm-p7eEzLCs.js.map +1 -0
- package/dist/baerly.js +35 -15
- package/dist/baerly.js.map +1 -1
- package/dist/baerly.spec.json +342 -0
- package/dist/{client-BJXF3XJA.d.ts → client-Fe8CwB73.d.ts} +3 -3
- package/dist/client-react.d.ts +3 -3
- package/dist/client-react.js +4 -4
- package/dist/client-react.js.map +1 -1
- package/dist/client.d.ts +4 -4
- package/dist/client.js +3 -3
- package/dist/{cloudflare-Cn2ibODt.js → cloudflare-DzKBrUlg.js} +2 -2
- package/dist/{cloudflare-Cn2ibODt.js.map → cloudflare-DzKBrUlg.js.map} +1 -1
- package/dist/cloudflare.d.ts +49 -6
- package/dist/cloudflare.js +55 -21
- package/dist/cloudflare.js.map +1 -1
- package/dist/config-1tv0-Yzm.js +2693 -0
- package/dist/config-1tv0-Yzm.js.map +1 -0
- package/dist/constants-CfeMWQWk.js +222 -0
- package/dist/constants-CfeMWQWk.js.map +1 -0
- package/dist/{cost-BZ_MDBmn.js → cost-DSMIVqzL.js} +42 -43
- package/dist/cost-DSMIVqzL.js.map +1 -0
- package/dist/{current-json-DsN7FNY1.js → current-json-C6nhPOm1.js} +6 -204
- package/dist/current-json-C6nhPOm1.js.map +1 -0
- package/dist/{db-CCT6tDfY.d.ts → db-DsPkOVEH.d.ts} +3 -3
- package/dist/{deploy-BKKyGlSJ.js → deploy-DonTr-CV.js} +4 -4
- package/dist/{deploy-BKKyGlSJ.js.map → deploy-DonTr-CV.js.map} +1 -1
- package/dist/dev-vite.d.ts +9 -5
- package/dist/dev-vite.js +5 -4
- package/dist/dev-vite.js.map +1 -1
- package/dist/dev.d.ts +1 -1
- package/dist/dev.js +1 -1
- package/dist/{doctor-BVU4GNXN.js → doctor-DSIyCDg_.js} +5 -8
- package/dist/{doctor-BVU4GNXN.js.map → doctor-DSIyCDg_.js.map} +1 -1
- package/dist/{dump-DPEAKub6.js → dump-Bh5k26VQ.js} +9 -32
- package/dist/dump-Bh5k26VQ.js.map +1 -0
- package/dist/{errors-DOdL95kK.js → errors-Dfa3p78c.js} +25 -5
- package/dist/errors-Dfa3p78c.js.map +1 -0
- package/dist/{export-BcuCLFFe.js → export-DtF5tDIM.js} +9 -32
- package/dist/{export-BcuCLFFe.js.map → export-DtF5tDIM.js.map} +1 -1
- package/dist/{fsck-RXgLOaJG.js → fsck-D_djMO5D.js} +10 -33
- package/dist/fsck-D_djMO5D.js.map +1 -0
- package/dist/{http-Bd4byR4n.js → http-DxM9MflO.js} +123 -35
- package/dist/http-DxM9MflO.js.map +1 -0
- package/dist/http.d.ts +42 -26
- package/dist/http.js +3 -2
- package/dist/{index-DnBGSeuU.d.ts → index-0rZcMBwy.d.ts} +2 -2
- package/dist/{index-Cmsxx-ZN.d.ts → index-B6oexfOB.d.ts} +7 -7
- package/dist/{index-BDceQQi-.d.ts → index-BNRh23K9.d.ts} +4 -4
- package/dist/{index-DW7GT6M2.d.ts → index-BYk9oCNf.d.ts} +193 -163
- package/dist/index.d.ts +6 -6
- package/dist/index.js +4 -4
- package/dist/{indexes-Cx7uMXm0.d.ts → indexes-Dn9hbGQG.d.ts} +2 -2
- package/dist/{inspect-DhI49PSi.js → inspect-6WZ-pC7-.js} +10 -33
- package/dist/inspect-6WZ-pC7-.js.map +1 -0
- package/dist/key-Di6yyxFu.js +35 -0
- package/dist/key-Di6yyxFu.js.map +1 -0
- package/dist/{log-tail-DXeDkWEp.js → log-tail-D98U1JBo.js} +31 -7
- package/dist/log-tail-D98U1JBo.js.map +1 -0
- package/dist/{maintenance-CWBQpZ2y.js → maintenance-B4Dki6Ig.js} +77 -22
- package/dist/maintenance-B4Dki6Ig.js.map +1 -0
- package/dist/{maintenance-BkhUr72A.d.ts → maintenance-B_e0T99L.d.ts} +28 -5
- package/dist/{maintenance-C_KSkVjd.js → maintenance-C7coQp4c.js} +17 -16
- package/dist/maintenance-C7coQp4c.js.map +1 -0
- package/dist/maintenance.d.ts +3 -3
- package/dist/maintenance.js +3 -3
- package/dist/node.d.ts +168 -65
- package/dist/node.js +3 -2
- package/dist/{normalize-XWY25_sG.js → normalize-rjnZLwS4.js} +2 -2
- package/dist/normalize-rjnZLwS4.js.map +1 -0
- package/dist/{observability-BYd-RzEx.js → observability-wzs3-BL_.js} +233 -71
- package/dist/observability-wzs3-BL_.js.map +1 -0
- package/dist/observability.d.ts +2 -2
- package/dist/observability.js +1 -1
- package/dist/{plan-DIu_B6fy.js → plan-a7PJHBCy.js} +2 -2
- package/dist/{plan-DIu_B6fy.js.map → plan-a7PJHBCy.js.map} +1 -1
- package/dist/{query-sQNO5vU_.js → query-rAtXNQQB.js} +96 -207
- package/dist/query-rAtXNQQB.js.map +1 -0
- package/dist/{rebuild-index-DP4CqSSs.js → rebuild-index-BVzQSZlm.js} +9 -32
- package/dist/rebuild-index-BVzQSZlm.js.map +1 -0
- package/dist/{request-BEF_OvMh.js → request-u0M51mhJ.js} +3 -3
- package/dist/{request-BEF_OvMh.js.map → request-u0M51mhJ.js.map} +1 -1
- package/dist/{restore-DpQYef6r.js → restore-R-4rbciV.js} +73 -100
- package/dist/restore-R-4rbciV.js.map +1 -0
- package/dist/runtime-spec-_GTdeSMo.js +391 -0
- package/dist/runtime-spec-_GTdeSMo.js.map +1 -0
- package/dist/s3-http-B-z8th6O.d.ts +60 -0
- package/dist/s3.d.ts +47 -0
- package/dist/s3.js +45 -0
- package/dist/s3.js.map +1 -0
- package/dist/{shared-secret-BJdSwpgw.js → shared-secret-DgEicd3x.js} +13 -5
- package/dist/shared-secret-DgEicd3x.js.map +1 -0
- package/dist/{src-Db4-qVtM.js → src-CYHFDrKz.js} +51 -8
- package/dist/src-CYHFDrKz.js.map +1 -0
- package/dist/{src-CWpkSbvJ.js → src-DYZ4H1aF.js} +6 -5
- package/dist/src-DYZ4H1aF.js.map +1 -0
- package/dist/src-D__mHQmQ.js +2271 -0
- package/dist/src-D__mHQmQ.js.map +1 -0
- package/dist/{subcommand-CP9NY2J4.js → subcommand-DoDA-K7d.js} +44 -6
- package/dist/subcommand-DoDA-K7d.js.map +1 -0
- package/dist/time-DUqvFMHq.js +119 -0
- package/dist/time-DUqvFMHq.js.map +1 -0
- package/dist/{usage-CTfDq9HR.js → usage-DBV1eQHC.js} +7 -22
- package/dist/usage-DBV1eQHC.js.map +1 -0
- package/dist/wire-izfGZDvr.js.map +1 -1
- package/package.json +51 -27
- package/dist/config-CGyBopy3.js +0 -5326
- package/dist/config-CGyBopy3.js.map +0 -1
- package/dist/cost-BZ_MDBmn.js.map +0 -1
- package/dist/current-json-DsN7FNY1.js.map +0 -1
- package/dist/dump-DPEAKub6.js.map +0 -1
- package/dist/errors-DOdL95kK.js.map +0 -1
- package/dist/fsck-RXgLOaJG.js.map +0 -1
- package/dist/http-Bd4byR4n.js.map +0 -1
- package/dist/inspect-DhI49PSi.js.map +0 -1
- package/dist/log-tail-DXeDkWEp.js.map +0 -1
- package/dist/maintenance-CWBQpZ2y.js.map +0 -1
- package/dist/maintenance-C_KSkVjd.js.map +0 -1
- package/dist/normalize-XWY25_sG.js.map +0 -1
- package/dist/observability-BYd-RzEx.js.map +0 -1
- package/dist/query-sQNO5vU_.js.map +0 -1
- package/dist/rebuild-index-DP4CqSSs.js.map +0 -1
- package/dist/restore-DpQYef6r.js.map +0 -1
- package/dist/shared-secret-BJdSwpgw.js.map +0 -1
- package/dist/src-CWpkSbvJ.js.map +0 -1
- package/dist/src-D24wDpzR.js +0 -6247
- package/dist/src-D24wDpzR.js.map +0 -1
- package/dist/src-Db4-qVtM.js.map +0 -1
- package/dist/subcommand-CP9NY2J4.js.map +0 -1
- package/dist/usage-CTfDq9HR.js.map +0 -1
- /package/dist/{chunk-EAsCxrDo.js → rolldown-runtime-EAsCxrDo.js} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { r as parseBucketUri } from "./config-
|
|
2
|
-
import { c as loadSnapshotAsMap, h as readCurrentJson } from "./log-tail-
|
|
3
|
-
import { i as rebuildIndex } from "./maintenance-
|
|
1
|
+
import { r as parseBucketUri } from "./config-1tv0-Yzm.js";
|
|
2
|
+
import { c as loadSnapshotAsMap, h as readCurrentJson } from "./log-tail-D98U1JBo.js";
|
|
3
|
+
import { i as rebuildIndex } from "./maintenance-C7coQp4c.js";
|
|
4
4
|
import { i as isJsonMode, o as BaerlyError, r as emitSuccess } from "./baerly.js";
|
|
5
|
-
import { n as defineBaerlySubcommand, t as
|
|
5
|
+
import { a as TENANT_ARG, i as JSON_ARG, n as BUCKET_ARG, o as assertCollectionArg, r as COLLECTION_ARG, s as defineBaerlySubcommand, t as APP_ARG } from "./subcommand-DoDA-K7d.js";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
7
|
//#region src/admin/fsck.ts
|
|
8
8
|
/**
|
|
@@ -51,30 +51,10 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
51
51
|
* `baerly admin` subcommands reserve 0–3.
|
|
52
52
|
*/
|
|
53
53
|
const FSCK_ARGS = {
|
|
54
|
-
bucket:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
valueHint: "bucket-uri"
|
|
59
|
-
},
|
|
60
|
-
app: {
|
|
61
|
-
type: "string",
|
|
62
|
-
required: false,
|
|
63
|
-
description: "Application name segment (defaults to baerly.config.ts).",
|
|
64
|
-
valueHint: "app"
|
|
65
|
-
},
|
|
66
|
-
tenant: {
|
|
67
|
-
type: "string",
|
|
68
|
-
required: false,
|
|
69
|
-
description: "Tenant name segment (defaults to baerly.config.ts).",
|
|
70
|
-
valueHint: "tenant"
|
|
71
|
-
},
|
|
72
|
-
collection: {
|
|
73
|
-
type: "string",
|
|
74
|
-
required: true,
|
|
75
|
-
description: "Collection name.",
|
|
76
|
-
valueHint: "name"
|
|
77
|
-
},
|
|
54
|
+
bucket: BUCKET_ARG,
|
|
55
|
+
app: APP_ARG,
|
|
56
|
+
tenant: TENANT_ARG,
|
|
57
|
+
collection: COLLECTION_ARG,
|
|
78
58
|
config: {
|
|
79
59
|
type: "string",
|
|
80
60
|
required: false,
|
|
@@ -89,10 +69,7 @@ const FSCK_ARGS = {
|
|
|
89
69
|
type: "boolean",
|
|
90
70
|
description: "With --indexes, rebuild drifted indexes (PUT missing keys, DELETE orphans). Rejected without --indexes."
|
|
91
71
|
},
|
|
92
|
-
json:
|
|
93
|
-
type: "boolean",
|
|
94
|
-
description: "Emit a structured JSON envelope to stdout (success) or stderr (error)"
|
|
95
|
-
}
|
|
72
|
+
json: JSON_ARG
|
|
96
73
|
};
|
|
97
74
|
/** Severities that count toward the exit-4 "findings present" status. */
|
|
98
75
|
const isFindingSeverity = (s) => s === "finding" || s === "warning";
|
|
@@ -299,4 +276,4 @@ bundle.run;
|
|
|
299
276
|
//#endregion
|
|
300
277
|
export { fsckCmd };
|
|
301
278
|
|
|
302
|
-
//# sourceMappingURL=fsck-
|
|
279
|
+
//# sourceMappingURL=fsck-D_djMO5D.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fsck-D_djMO5D.js","names":[],"sources":["../packages/cli/src/admin/fsck.ts"],"sourcesContent":["/**\n * `baerly admin fsck` — consistency walk for one collection.\n *\n * Default mode (no `--indexes`): read-only checks against the\n * snapshot + log tail.\n * 1. `current.json` exists at the expected key and parses.\n * 2. When `current.snapshot !== null`, the snapshot body's\n * SHA-256 matches the hash embedded in the filename\n * (delegated to `loadSnapshotAsMap`).\n * 3. The live log range has no holes. The upper bound is derived\n * from a single LIST of `log/` plus `current.json.tail_hint`\n * (max(highest present seq + 1, tail_hint)), and every seq from\n * `log_seq_start` up to that tail must be present.\n * This is a presence/hole check by key, NOT a per-entry decode:\n * fsck does not GET and parse each `log/<seq>.json`, so it does\n * not assert every entry is well-formed JSON or carries the locked\n * `op`/`collection`/`doc_id` fields. A full decode walk is\n * intentionally omitted to keep the op count O(LIST pages); the\n * read path validates entry shape at fold time.\n *\n * `--indexes` + `--config=<path>` mode: SKIP the snapshot + log\n * walks and ONLY check each declared index for drift via\n * `rebuildIndex(..., { dryRun: true })`. Drift is `(added > 0)`\n * (rows that should be projected but have no key on storage) or\n * `(removed > 0)` (orphan keys for rows that no longer match).\n * Read-only.\n *\n * `--indexes --fix`: same drift walk but with `dryRun: false`, so\n * `rebuildIndex` PUTs missing keys and DELETEs orphans. The findings\n * downgrade from `warning` to `info` (drift was found AND fixed in\n * one pass). `--fix` without `--indexes` is rejected — fsck has no\n * auto-fix outside the index check.\n *\n * Exit codes:\n * 0 — all checks pass.\n * 1 — InvalidConfig (bad bucket URI, missing args, unknown flag,\n * `--fix` without `--indexes`).\n * 2 — Storage / Network error during the walk.\n * 3 — Protocol invariant violation surfaced by the kernel\n * (Internal / InvalidResponse) — distinguished from exit 4\n * so CI can wire fsck as a regression gate.\n * 4 — One or more findings (orphan / hole / hash-mismatch /\n * index drift). Unique to this command; the other\n * `baerly admin` subcommands reserve 0–3.\n */\n\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { type ArgsDef } from \"citty\";\nimport {\n type BaerlyConfig,\n BaerlyError,\n type IndexDefinition,\n readCurrentJson,\n type Storage,\n} from \"@baerly/protocol\";\nimport { loadSnapshotAsMap } from \"@baerly/server\";\nimport { rebuildIndex } from \"@baerly/server/maintenance\";\nimport { parseBucketUri } from \"../bucket-uri.ts\";\nimport { emitSuccess, isJsonMode } from \"../output.ts\";\nimport {\n APP_ARG,\n assertCollectionArg,\n BUCKET_ARG,\n COLLECTION_ARG,\n defineBaerlySubcommand,\n JSON_ARG,\n TENANT_ARG,\n} from \"../subcommand.ts\";\n\nconst FSCK_ARGS = {\n bucket: BUCKET_ARG,\n app: APP_ARG,\n tenant: TENANT_ARG,\n collection: COLLECTION_ARG,\n config: {\n type: \"string\",\n required: false,\n description:\n \"Path to baerly.config.{js,mjs,json}. Required with --indexes; resolves index definitions.\",\n valueHint: \"path\",\n },\n indexes: {\n type: \"boolean\",\n description:\n \"Skip snapshot + log walks; check declared indexes for drift via rebuildIndex (read-only by default).\",\n },\n fix: {\n type: \"boolean\",\n description:\n \"With --indexes, rebuild drifted indexes (PUT missing keys, DELETE orphans). Rejected without --indexes.\",\n },\n json: JSON_ARG,\n} as const satisfies ArgsDef;\n\ntype Severity = \"ok\" | \"info\" | \"warning\" | \"finding\";\ninterface Finding {\n readonly severity: Severity;\n readonly check: string;\n readonly message: string;\n readonly key?: string;\n}\n\n/** Severities that count toward the exit-4 \"findings present\" status. */\nconst isFindingSeverity = (s: Severity): boolean => s === \"finding\" || s === \"warning\";\n\nconst loadConfigIndexes = async (\n configPath: string,\n collection: string,\n): Promise<readonly IndexDefinition[]> => {\n if (configPath.endsWith(\".ts\")) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `baerly admin fsck: --config must point at compiled JS / JSON (got .ts: ${JSON.stringify(configPath)})`,\n );\n }\n let cfg: BaerlyConfig;\n if (configPath.endsWith(\".json\")) {\n const { readFile } = await import(\"node:fs/promises\");\n const text = await readFile(configPath, \"utf8\");\n try {\n cfg = JSON.parse(text) as BaerlyConfig;\n } catch (error) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `baerly admin fsck: --config JSON parse error in ${JSON.stringify(configPath)}: ${(error as Error).message}`,\n );\n }\n } else {\n const pathMod = await import(\"node:path\");\n const abs = configPath.startsWith(\"file://\")\n ? fileURLToPath(configPath)\n : pathMod.resolve(configPath);\n const mod = (await import(pathToFileURL(abs).href)) as { default?: BaerlyConfig };\n if (mod.default === undefined) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `baerly admin fsck: --config ${JSON.stringify(configPath)} has no default export`,\n );\n }\n cfg = mod.default;\n }\n const def = cfg.collections?.[collection];\n return def?.indexes ?? [];\n};\n\nconst listKeys = async (storage: Storage, prefix: string): Promise<string[]> => {\n const out: string[] = [];\n for await (const entry of storage.list(prefix)) {\n out.push(entry.key);\n }\n return out.toSorted();\n};\n\nconst statusLine = (label: string, ok: boolean, detail: string): string =>\n ` ${label.padEnd(22)}${ok ? \"ok\" : \"error\"} ${detail}`.trimEnd();\n\ninterface IndexSummary {\n readonly name: string;\n readonly added: number;\n readonly removed: number;\n readonly kept: number;\n readonly rebuilt: boolean;\n}\n\nconst renderSnapshotLog = (\n collection: string,\n findings: readonly Finding[],\n context: {\n readonly logRange: readonly [number, number];\n readonly logEntriesPresent: number;\n readonly snapshotKey: string | null;\n },\n): string => {\n const lines: string[] = [];\n lines.push(`baerly admin fsck ${collection}`);\n const [from, toExcl] = context.logRange;\n const byCheck = new Map<string, Finding[]>();\n for (const f of findings) {\n const arr = byCheck.get(f.check) ?? [];\n arr.push(f);\n byCheck.set(f.check, arr);\n }\n lines.push(statusLine(\"current.json:\", (byCheck.get(\"current.json\") ?? []).length === 0, \"\"));\n lines.push(\n statusLine(\n \"snapshot hash:\",\n (byCheck.get(\"snapshot\") ?? []).length === 0,\n context.snapshotKey === null ? \"(no snapshot yet)\" : `(sha256 verified)`,\n ),\n );\n lines.push(\n statusLine(\n `log range [${from},${toExcl}):`,\n (byCheck.get(\"log\") ?? []).length === 0,\n `(${context.logEntriesPresent}/${toExcl - from} entries present)`,\n ),\n );\n lines.push(` status: ${findings.some(isFindingFinding) ? \"findings\" : \"ok\"}`);\n for (const f of findings) {\n lines.push(` ${f.check}: ${f.message}${f.key !== undefined ? ` (key=${f.key})` : \"\"}`);\n }\n return lines.join(\"\\n\") + \"\\n\";\n};\n\nconst renderIndexes = (\n collection: string,\n findings: readonly Finding[],\n summaries: readonly IndexSummary[],\n fix: boolean,\n): string => {\n const lines: string[] = [];\n lines.push(`baerly admin fsck ${collection} --indexes${fix ? \" --fix\" : \"\"}`);\n for (const s of summaries) {\n const verb = s.rebuilt ? \"rebuilt\" : \"would rebuild\";\n if (s.added === 0 && s.removed === 0) {\n lines.push(` ${s.name}: in sync (${s.kept} keys)`);\n } else {\n lines.push(` ${s.name}: ${verb} — added ${s.added}, removed ${s.removed}, kept ${s.kept}`);\n }\n }\n lines.push(` status: ${findings.some(isFindingFinding) ? \"findings\" : \"ok\"}`);\n for (const f of findings) {\n if (f.check === \"log\" || f.check === \"snapshot\" || f.check === \"current.json\") {\n continue;\n }\n lines.push(` ${f.check}: ${f.message}${f.key !== undefined ? ` (key=${f.key})` : \"\"}`);\n }\n return lines.join(\"\\n\") + \"\\n\";\n};\n\nconst isFindingFinding = (f: Finding): boolean => isFindingSeverity(f.severity);\n\nconst bundle = defineBaerlySubcommand({\n name: \"admin.fsck\",\n meta: {\n description: \"Read-only consistency walk for one collection.\",\n },\n args: FSCK_ARGS,\n handler: async (args, ctx) => {\n const indexMode = args.indexes === true;\n const fixMode = args.fix === true;\n if (fixMode && !indexMode) {\n throw new BaerlyError(\n \"InvalidConfig\",\n \"baerly admin fsck: --fix is only valid with --indexes (fsck has no auto-fix outside the index check)\",\n );\n }\n if (indexMode && (args.config === undefined || args.config.length === 0)) {\n throw new BaerlyError(\n \"InvalidConfig\",\n \"baerly admin fsck: --indexes requires --config=<path> to resolve index definitions\",\n );\n }\n const { app, tenant } = await ctx.resolveAppTenant({ app: args.app, tenant: args.tenant });\n assertCollectionArg(args.collection, \"baerly admin fsck\");\n const bucket = await parseBucketUri(args.bucket);\n const collectionPrefix = `${bucket.keyPrefix}app/${app}/tenant/${tenant}/manifests/${args.collection}`;\n const currentJsonKey = `${collectionPrefix}/current.json`;\n\n const findings: Finding[] = [];\n\n if (indexMode) {\n // ── Index drift mode. ──────────────────────────────────────────\n // Skip snapshot + log walks. For each declared index, call\n // `rebuildIndex(..., { dryRun: !fix })` — it returns the\n // `(added, removed, kept)` triple we need to call drift.\n const defs = await loadConfigIndexes(args.config!, args.collection);\n const summaries: IndexSummary[] = [];\n for (const def of defs) {\n const check = `index.${def.name}`;\n let result;\n try {\n result = await rebuildIndex(bucket.storage, currentJsonKey, def, {\n dryRun: !fixMode,\n });\n } catch (error) {\n findings.push({\n severity: \"finding\",\n check,\n message: `${def.name}: drift check failed: ${(error as Error).message}`,\n });\n continue;\n }\n const summary: IndexSummary = {\n name: def.name,\n added: result.added,\n removed: result.removed,\n kept: result.kept,\n rebuilt: fixMode,\n };\n summaries.push(summary);\n const drifted = result.added > 0 || result.removed > 0;\n if (!drifted) {\n findings.push({\n severity: \"ok\",\n check,\n message: `${def.name}: in sync (${result.kept} keys).`,\n });\n } else if (fixMode) {\n findings.push({\n severity: \"info\",\n check,\n message: `${def.name}: rebuilt — added ${result.added}, removed ${result.removed}, kept ${result.kept}.`,\n });\n } else {\n findings.push({\n severity: \"warning\",\n check,\n message: `${def.name}: drift detected — ${result.added} missing, ${result.removed} orphaned (${result.kept} in sync).`,\n });\n }\n }\n\n if (isJsonMode()) {\n emitSuccess({\n command: \"admin.fsck\",\n status: findings.some(isFindingFinding) ? \"findings\" : \"ok\",\n collection: args.collection,\n mode: fixMode ? \"indexes-fix\" : \"indexes\",\n indexes: summaries,\n findings: findings.map((f) => ({\n severity: f.severity,\n check: f.check,\n message: f.message,\n ...(f.key !== undefined && { key: f.key }),\n })),\n });\n } else {\n process.stdout.write(renderIndexes(args.collection, findings, summaries, fixMode));\n }\n return findings.some(isFindingFinding) ? 4 : 0;\n }\n\n // ── Default mode. current.json + snapshot + log walks. ─────────\n const read = await readCurrentJson(bucket.storage, currentJsonKey);\n if (read === null) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `baerly admin fsck: current.json not found at ${currentJsonKey}`,\n );\n }\n const cur = read.json;\n const logFrom = cur.log_seq_start ?? 0;\n const snapshotKey = cur.snapshot;\n\n // ── Snapshot hash verifies (loadSnapshotAsMap throws on mismatch). ──\n if (snapshotKey !== null) {\n try {\n await loadSnapshotAsMap(bucket.storage, snapshotKey, args.collection);\n } catch (error) {\n if (\n error instanceof BaerlyError &&\n (error.code === \"Internal\" || error.code === \"InvalidResponse\")\n ) {\n findings.push({\n severity: \"finding\",\n check: \"snapshot\",\n message: error.message,\n key: snapshotKey,\n });\n } else {\n throw error;\n }\n }\n }\n\n // ── Log range [from, tail) has no holes (presence check only). ──\n // LIST the log/ prefix and derive the upper bound from both listed\n // keys and `tail_hint`: under single-write commit `tail_hint` is\n // normally a lower bound, but fsck must also catch an over-claimed\n // hint whose `[log_seq_start, tail_hint)` range is not actually\n // present. Use a single LIST so the op count is O(pages).\n const logPrefix = `${collectionPrefix}/log/`;\n const presentKeys = await listKeys(bucket.storage, logPrefix);\n const presentSeqs = new Set<number>();\n let maxSeq = logFrom - 1;\n for (const key of presentKeys) {\n const tail = key.slice(logPrefix.length);\n const match = /^(\\d+)\\.json$/.exec(tail);\n if (match === null) {\n continue;\n }\n const seq = Number.parseInt(match[1]!, 10);\n if (Number.isFinite(seq)) {\n presentSeqs.add(seq);\n if (seq > maxSeq) {\n maxSeq = seq;\n }\n }\n }\n const logToExcl = Math.max(cur.tail_hint, maxSeq + 1);\n let logEntriesPresent = 0;\n for (let s = logFrom; s < logToExcl; s++) {\n if (presentSeqs.has(s)) {\n logEntriesPresent++;\n } else {\n findings.push({\n severity: \"finding\",\n check: \"log\",\n message: `missing log entry at seq ${s} inside [log_seq_start, tail)`,\n key: `${logPrefix}${s}.json`,\n });\n }\n }\n\n if (isJsonMode()) {\n emitSuccess({\n command: \"admin.fsck\",\n status: findings.some(isFindingFinding) ? \"findings\" : \"ok\",\n collection: args.collection,\n current_json_key: currentJsonKey,\n snapshot: snapshotKey,\n log_range: { from: logFrom, to_excl: logToExcl, present: logEntriesPresent },\n findings: findings.map((f) => ({\n severity: f.severity,\n check: f.check,\n message: f.message,\n ...(f.key !== undefined && { key: f.key }),\n })),\n });\n } else {\n process.stdout.write(\n renderSnapshotLog(args.collection, findings, {\n logRange: [logFrom, logToExcl],\n logEntriesPresent,\n snapshotKey,\n }),\n );\n }\n return findings.some(isFindingFinding) ? 4 : 0;\n },\n});\n\n/** citty `defineCommand` block for `baerly admin fsck`. */\nexport const fsckCmd = bundle.cmd;\n\n/**\n * Programmatic entry used by tests. Bypasses citty's `run` wrapper\n * (which would call `process.exit` and kill vitest) and returns the\n * integer exit code directly.\n */\nexport const runFsck = bundle.run;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEA,MAAM,YAAY;CAChB,QAAQ;CACR,KAAK;CACL,QAAQ;CACR,YAAY;CACZ,QAAQ;EACN,MAAM;EACN,UAAU;EACV,aACE;EACF,WAAW;CACb;CACA,SAAS;EACP,MAAM;EACN,aACE;CACJ;CACA,KAAK;EACH,MAAM;EACN,aACE;CACJ;CACA,MAAM;AACR;;AAWA,MAAM,qBAAqB,MAAyB,MAAM,aAAa,MAAM;AAE7E,MAAM,oBAAoB,OACxB,YACA,eACwC;CACxC,IAAI,WAAW,SAAS,KAAK,GAC3B,MAAM,IAAI,YACR,iBACA,0EAA0E,KAAK,UAAU,UAAU,EAAE,EACvG;CAEF,IAAI;CACJ,IAAI,WAAW,SAAS,OAAO,GAAG;EAChC,MAAM,EAAE,aAAa,MAAM,OAAO;EAClC,MAAM,OAAO,MAAM,SAAS,YAAY,MAAM;EAC9C,IAAI;GACF,MAAM,KAAK,MAAM,IAAI;EACvB,SAAS,OAAO;GACd,MAAM,IAAI,YACR,iBACA,mDAAmD,KAAK,UAAU,UAAU,EAAE,IAAK,MAAgB,SACrG;EACF;CACF,OAAO;EACL,MAAM,UAAU,MAAM,OAAO;EAI7B,MAAM,MAAO,MAAM,OAAO,cAHd,WAAW,WAAW,SAAS,IACvC,cAAc,UAAU,IACxB,QAAQ,QAAQ,UAAU,CACa,CAAC,CAAC;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AAS,MAAM,IAAK,EAAE;GACzC,IAAI,OAAO,SAAS,GAAG,GAAG;IACxB,YAAY,IAAI,GAAG;IACnB,IAAI,MAAM,QACR,SAAS;GAEb;EACF;EACA,MAAM,YAAY,KAAK,IAAI,IAAI,WAAW,SAAS,CAAC;EACpD,IAAI,oBAAoB;EACxB,KAAK,IAAI,IAAI,SAAS,IAAI,WAAW,KACnC,IAAI,YAAY,IAAI,CAAC,GACnB;OAEA,SAAS,KAAK;GACZ,UAAU;GACV,OAAO;GACP,SAAS,4BAA4B,EAAE;GACvC,KAAK,GAAG,YAAY,EAAE;EACxB,CAAC;EAIL,IAAI,WAAW,GACb,YAAY;GACV,SAAS;GACT,QAAQ,SAAS,KAAK,gBAAgB,IAAI,aAAa;GACvD,YAAY,KAAK;GACjB,kBAAkB;GAClB,UAAU;GACV,WAAW;IAAE,MAAM;IAAS,SAAS;IAAW,SAAS;GAAkB;GAC3E,UAAU,SAAS,KAAK,OAAO;IAC7B,UAAU,EAAE;IACZ,OAAO,EAAE;IACT,SAAS,EAAE;IACX,GAAI,EAAE,QAAQ,KAAA,KAAa,EAAE,KAAK,EAAE,IAAI;GAC1C,EAAE;EACJ,CAAC;OAED,QAAQ,OAAO,MACb,kBAAkB,KAAK,YAAY,UAAU;GAC3C,UAAU,CAAC,SAAS,SAAS;GAC7B;GACA;EACF,CAAC,CACH;EAEF,OAAO,SAAS,KAAK,gBAAgB,IAAI,IAAI;CAC/C;AACF,CAAC;;AAGD,MAAa,UAAU,OAAO;AAOP,OAAO"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { d as WHERE_ORDER_JSON_RESOLUTION, f as WRITE_BODY_SHAPE_RESOLUTION, i as serializeError, l as getLogger, s as CATEGORY, u as errorEnvelope } from "./observability-wzs3-BL_.js";
|
|
2
|
+
import { r as logSeqStartOf } from "./current-json-C6nhPOm1.js";
|
|
3
|
+
import { t as BaerlyError } from "./errors-Dfa3p78c.js";
|
|
4
|
+
import { D as validateWire } from "./maintenance-B4Dki6Ig.js";
|
|
5
|
+
import { n as runAllWithMeta, r as runByIdWithMeta } from "./query-rAtXNQQB.js";
|
|
5
6
|
import { t as EMPTY_PREDICATE_WIRE } from "./wire-izfGZDvr.js";
|
|
6
|
-
import { i as
|
|
7
|
+
import { i as str2uintDesc } from "./time-DUqvFMHq.js";
|
|
8
|
+
import { n as getCurrentContext } from "./context-DRZ3tZ5l.js";
|
|
7
9
|
//#region packages/protocol/src/log.ts
|
|
8
10
|
/**
|
|
9
11
|
* Extract the `session` and `seq` embedded in an `lsn` of shape
|
|
@@ -28,7 +30,7 @@ const lsnParts = (lsn) => {
|
|
|
28
30
|
};
|
|
29
31
|
};
|
|
30
32
|
//#endregion
|
|
31
|
-
//#region node_modules/.pnpm/hono@4.12.
|
|
33
|
+
//#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/compose.js
|
|
32
34
|
var compose = (middleware, onError, onNotFound) => {
|
|
33
35
|
return (context, next) => {
|
|
34
36
|
let index = -1;
|
|
@@ -59,10 +61,10 @@ var compose = (middleware, onError, onNotFound) => {
|
|
|
59
61
|
};
|
|
60
62
|
};
|
|
61
63
|
//#endregion
|
|
62
|
-
//#region node_modules/.pnpm/hono@4.12.
|
|
64
|
+
//#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/request/constants.js
|
|
63
65
|
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
64
66
|
//#endregion
|
|
65
|
-
//#region node_modules/.pnpm/hono@4.12.
|
|
67
|
+
//#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/utils/body.js
|
|
66
68
|
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
67
69
|
const { all = false, dot = false } = options;
|
|
68
70
|
const contentType = (request instanceof HonoRequest ? request.raw.headers : request.headers).get("Content-Type");
|
|
@@ -110,7 +112,7 @@ var handleParsingNestedValues = (form, key, value) => {
|
|
|
110
112
|
});
|
|
111
113
|
};
|
|
112
114
|
//#endregion
|
|
113
|
-
//#region node_modules/.pnpm/hono@4.12.
|
|
115
|
+
//#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/utils/url.js
|
|
114
116
|
var tryDecode = (str, decoder) => {
|
|
115
117
|
try {
|
|
116
118
|
return decoder(str);
|
|
@@ -202,7 +204,7 @@ var getQueryParams = (url, key) => {
|
|
|
202
204
|
};
|
|
203
205
|
var decodeURIComponent_ = decodeURIComponent;
|
|
204
206
|
//#endregion
|
|
205
|
-
//#region node_modules/.pnpm/hono@4.12.
|
|
207
|
+
//#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/request.js
|
|
206
208
|
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
207
209
|
var HonoRequest = class {
|
|
208
210
|
/**
|
|
@@ -474,7 +476,7 @@ var HonoRequest = class {
|
|
|
474
476
|
}
|
|
475
477
|
};
|
|
476
478
|
//#endregion
|
|
477
|
-
//#region node_modules/.pnpm/hono@4.12.
|
|
479
|
+
//#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/utils/html.js
|
|
478
480
|
var HtmlEscapedCallbackPhase = {
|
|
479
481
|
Stringify: 1,
|
|
480
482
|
BeforeStream: 2,
|
|
@@ -504,7 +506,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
|
|
|
504
506
|
else return resStr;
|
|
505
507
|
};
|
|
506
508
|
//#endregion
|
|
507
|
-
//#region node_modules/.pnpm/hono@4.12.
|
|
509
|
+
//#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/context.js
|
|
508
510
|
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
509
511
|
var setDefaultContentType = (contentType, headers) => {
|
|
510
512
|
return {
|
|
@@ -865,7 +867,7 @@ var Context = class {
|
|
|
865
867
|
};
|
|
866
868
|
};
|
|
867
869
|
//#endregion
|
|
868
|
-
//#region node_modules/.pnpm/hono@4.12.
|
|
870
|
+
//#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/router.js
|
|
869
871
|
var METHODS = [
|
|
870
872
|
"get",
|
|
871
873
|
"post",
|
|
@@ -876,10 +878,10 @@ var METHODS = [
|
|
|
876
878
|
];
|
|
877
879
|
var UnsupportedPathError = class extends Error {};
|
|
878
880
|
//#endregion
|
|
879
|
-
//#region node_modules/.pnpm/hono@4.12.
|
|
881
|
+
//#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/utils/constants.js
|
|
880
882
|
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
881
883
|
//#endregion
|
|
882
|
-
//#region node_modules/.pnpm/hono@4.12.
|
|
884
|
+
//#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/hono-base.js
|
|
883
885
|
var notFoundHandler = (c) => {
|
|
884
886
|
return c.text("404 Not Found", 404);
|
|
885
887
|
};
|
|
@@ -1213,7 +1215,7 @@ var Hono$1 = class _Hono {
|
|
|
1213
1215
|
};
|
|
1214
1216
|
};
|
|
1215
1217
|
//#endregion
|
|
1216
|
-
//#region node_modules/.pnpm/hono@4.12.
|
|
1218
|
+
//#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/router/pattern-router/router.js
|
|
1217
1219
|
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
1218
1220
|
var PatternRouter = class {
|
|
1219
1221
|
name = "PatternRouter";
|
|
@@ -1252,7 +1254,7 @@ var PatternRouter = class {
|
|
|
1252
1254
|
}
|
|
1253
1255
|
};
|
|
1254
1256
|
//#endregion
|
|
1255
|
-
//#region node_modules/.pnpm/hono@4.12.
|
|
1257
|
+
//#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/preset/tiny.js
|
|
1256
1258
|
var Hono = class extends Hono$1 {
|
|
1257
1259
|
constructor(options = {}) {
|
|
1258
1260
|
super(options);
|
|
@@ -1536,7 +1538,7 @@ function createRouter(options) {
|
|
|
1536
1538
|
});
|
|
1537
1539
|
app.get("/v1/count", async (c) => {
|
|
1538
1540
|
const collection = c.req.query("collection");
|
|
1539
|
-
if (collection === void 0 || collection.length === 0) throw new BaerlyError("SchemaError", "GET /v1/count requires ?collection=<name>");
|
|
1541
|
+
if (collection === void 0 || collection.length === 0) throw new BaerlyError("SchemaError", "GET /v1/count requires ?collection=<name>", void 0, void 0, void 0, "Add ?collection=<name> to the request URL.");
|
|
1540
1542
|
const wire = parseWhereParam(c);
|
|
1541
1543
|
const { rows, manifestPointer, fresh } = await runAllWithMeta(db.collectionReadContext(collection), {
|
|
1542
1544
|
wire,
|
|
@@ -1599,7 +1601,7 @@ const MAX_BODY_BYTES = 1 << 20;
|
|
|
1599
1601
|
*/
|
|
1600
1602
|
const assertJsonBodyField = (body, field) => {
|
|
1601
1603
|
const value = typeof body === "object" && body !== null ? body[field] : void 0;
|
|
1602
|
-
if (value === void 0 || typeof value !== "object" || value === null || Array.isArray(value)) throw new BaerlyError("SchemaError", `Request body must be { ${field}: object }
|
|
1604
|
+
if (value === void 0 || typeof value !== "object" || value === null || Array.isArray(value)) throw new BaerlyError("SchemaError", `Request body must be { ${field}: object }`, void 0, void 0, void 0, WRITE_BODY_SHAPE_RESOLUTION);
|
|
1603
1605
|
return value;
|
|
1604
1606
|
};
|
|
1605
1607
|
/**
|
|
@@ -1627,9 +1629,13 @@ const parseWhereParam = (c) => {
|
|
|
1627
1629
|
try {
|
|
1628
1630
|
parsed = JSON.parse(whereParam);
|
|
1629
1631
|
} catch {
|
|
1630
|
-
throw new BaerlyError("SchemaError", "Invalid JSON in ?where=");
|
|
1632
|
+
throw new BaerlyError("SchemaError", "Invalid JSON in ?where=", void 0, void 0, void 0, WHERE_ORDER_JSON_RESOLUTION);
|
|
1633
|
+
}
|
|
1634
|
+
try {
|
|
1635
|
+
return validateWire(parsed);
|
|
1636
|
+
} catch (error) {
|
|
1637
|
+
throw markCallerFacingInvalidConfig(error);
|
|
1631
1638
|
}
|
|
1632
|
-
return validateWire(parsed);
|
|
1633
1639
|
};
|
|
1634
1640
|
/**
|
|
1635
1641
|
* Parse `?limit=<n>` as a non-negative safe integer. Returns
|
|
@@ -1658,36 +1664,118 @@ function parseOrder(raw) {
|
|
|
1658
1664
|
try {
|
|
1659
1665
|
parsed = JSON.parse(raw);
|
|
1660
1666
|
} catch {
|
|
1661
|
-
throw new BaerlyError("SchemaError", "Invalid JSON in ?order=");
|
|
1667
|
+
throw new BaerlyError("SchemaError", "Invalid JSON in ?order=", void 0, void 0, void 0, WHERE_ORDER_JSON_RESOLUTION);
|
|
1662
1668
|
}
|
|
1663
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new BaerlyError("SchemaError", "?order= must encode a JSON object");
|
|
1669
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new BaerlyError("SchemaError", "?order= must encode a JSON object", void 0, void 0, void 0, WHERE_ORDER_JSON_RESOLUTION);
|
|
1664
1670
|
return parsed;
|
|
1665
1671
|
}
|
|
1666
|
-
const ERROR_TO_STATUS = new Map([
|
|
1672
|
+
const ERROR_TO_STATUS = /* @__PURE__ */ new Map([
|
|
1667
1673
|
["Unauthorized", 401],
|
|
1668
1674
|
["AccessDenied", 403],
|
|
1669
1675
|
["NotFound", 404],
|
|
1670
1676
|
["Conflict", 409],
|
|
1671
1677
|
["PayloadTooLarge", 413],
|
|
1672
1678
|
["SchemaError", 400],
|
|
1673
|
-
["InvalidConfig", 400]
|
|
1679
|
+
["InvalidConfig", 400],
|
|
1680
|
+
["UnsatisfiablePredicate", 400],
|
|
1681
|
+
["NetworkError", 502],
|
|
1682
|
+
["InvalidResponse", 502]
|
|
1674
1683
|
]);
|
|
1684
|
+
const CALLER_FACING_INVALID_CONFIG_ERRORS = /* @__PURE__ */ new WeakSet();
|
|
1685
|
+
const ERROR_CODE_POLICY = {
|
|
1686
|
+
AccessDenied: {
|
|
1687
|
+
messagePolicy: "scrubbed",
|
|
1688
|
+
scrubbedMessage: "access denied"
|
|
1689
|
+
},
|
|
1690
|
+
Conflict: {
|
|
1691
|
+
messagePolicy: "contextual",
|
|
1692
|
+
scrubbedMessage: "write conflict",
|
|
1693
|
+
shouldExpose: (err) => !err.retriable
|
|
1694
|
+
},
|
|
1695
|
+
Internal: {
|
|
1696
|
+
messagePolicy: "scrubbed",
|
|
1697
|
+
scrubbedMessage: "internal error"
|
|
1698
|
+
},
|
|
1699
|
+
InvalidConfig: {
|
|
1700
|
+
messagePolicy: "contextual",
|
|
1701
|
+
scrubbedMessage: "invalid server configuration",
|
|
1702
|
+
shouldExpose: (err) => CALLER_FACING_INVALID_CONFIG_ERRORS.has(err)
|
|
1703
|
+
},
|
|
1704
|
+
InvalidResponse: {
|
|
1705
|
+
messagePolicy: "scrubbed",
|
|
1706
|
+
scrubbedMessage: "upstream response error"
|
|
1707
|
+
},
|
|
1708
|
+
MutationFailed: {
|
|
1709
|
+
messagePolicy: "scrubbed",
|
|
1710
|
+
scrubbedMessage: "internal error"
|
|
1711
|
+
},
|
|
1712
|
+
NetworkError: {
|
|
1713
|
+
messagePolicy: "scrubbed",
|
|
1714
|
+
scrubbedMessage: "upstream network error"
|
|
1715
|
+
},
|
|
1716
|
+
NotFound: { messagePolicy: "public" },
|
|
1717
|
+
PayloadTooLarge: { messagePolicy: "public" },
|
|
1718
|
+
SchemaError: { messagePolicy: "public" },
|
|
1719
|
+
Unauthorized: { messagePolicy: "public" },
|
|
1720
|
+
UnexpectedWriteInQuery: {
|
|
1721
|
+
messagePolicy: "scrubbed",
|
|
1722
|
+
scrubbedMessage: "internal error"
|
|
1723
|
+
},
|
|
1724
|
+
UnsatisfiablePredicate: { messagePolicy: "public" },
|
|
1725
|
+
UseQueryAwaitedRecorder: {
|
|
1726
|
+
messagePolicy: "scrubbed",
|
|
1727
|
+
scrubbedMessage: "internal error"
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
const markCallerFacingInvalidConfig = (err) => {
|
|
1731
|
+
if (err instanceof BaerlyError && err.code === "InvalidConfig") CALLER_FACING_INVALID_CONFIG_ERRORS.add(err);
|
|
1732
|
+
return err;
|
|
1733
|
+
};
|
|
1734
|
+
const shouldExposeErrorMessage = (err) => {
|
|
1735
|
+
const policy = ERROR_CODE_POLICY[err.code];
|
|
1736
|
+
if (policy.messagePolicy === "public") return true;
|
|
1737
|
+
if (policy.messagePolicy === "scrubbed") return false;
|
|
1738
|
+
return policy.shouldExpose(err);
|
|
1739
|
+
};
|
|
1740
|
+
const scrubbedMessageFor = (code) => {
|
|
1741
|
+
const policy = ERROR_CODE_POLICY[code];
|
|
1742
|
+
return policy.messagePolicy === "public" ? "internal error" : policy.scrubbedMessage;
|
|
1743
|
+
};
|
|
1744
|
+
const logScrubbedError = (err, status) => {
|
|
1745
|
+
const ctx = getCurrentContext();
|
|
1746
|
+
getLogger(CATEGORY.http).error("scrubbed_error", {
|
|
1747
|
+
error: serializeError(err),
|
|
1748
|
+
status,
|
|
1749
|
+
...ctx !== void 0 ? { request_id: ctx.request_id } : {}
|
|
1750
|
+
});
|
|
1751
|
+
};
|
|
1675
1752
|
/**
|
|
1676
1753
|
* Map an unknown thrown value onto the wire envelope plus an HTTP
|
|
1677
1754
|
* status code. The mapping is keyed by `BaerlyError.code` so any future
|
|
1678
|
-
* code addition forces a re-check here
|
|
1679
|
-
* through to 500 by design —
|
|
1680
|
-
* / `Internal` comment in `ERROR_TO_STATUS`).
|
|
1755
|
+
* code addition forces a re-check here. Unmapped server-side codes fall
|
|
1756
|
+
* through to 500 by design — currently only `Internal`.
|
|
1681
1757
|
*
|
|
1682
1758
|
* Public via `@gusto/baerly-storage/http` for the embed-by-hand recipe
|
|
1683
1759
|
* (your own Hono / Express / Fastify app calling `Db` directly).
|
|
1684
1760
|
* The `HttpErrorEnvelope` shape is locked; do not mutate it.
|
|
1685
1761
|
*/
|
|
1686
1762
|
function mapError(err) {
|
|
1687
|
-
if (err instanceof BaerlyError)
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1763
|
+
if (err instanceof BaerlyError) {
|
|
1764
|
+
const mappedStatus = ERROR_TO_STATUS.get(err.code);
|
|
1765
|
+
const status = mappedStatus ?? 500;
|
|
1766
|
+
const wireCode = mappedStatus === void 0 ? "Internal" : err.code;
|
|
1767
|
+
if (wireCode !== err.code || !shouldExposeErrorMessage(err)) {
|
|
1768
|
+
logScrubbedError(err, status);
|
|
1769
|
+
return {
|
|
1770
|
+
status,
|
|
1771
|
+
envelope: errorEnvelope(wireCode, scrubbedMessageFor(wireCode), void 0, wireCode === "Conflict" ? err.resolution : void 0, wireCode === err.code ? err.retriable : void 0)
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
return {
|
|
1775
|
+
status,
|
|
1776
|
+
envelope: errorEnvelope(err.code, err.message, err.issues, err.resolution, err.retriable)
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1691
1779
|
getLogger(CATEGORY.http).error("unhandled_error", { error: serializeError(err) });
|
|
1692
1780
|
return {
|
|
1693
1781
|
status: 500,
|
|
@@ -1727,14 +1815,14 @@ async function readJsonBody(c, maxBytes) {
|
|
|
1727
1815
|
if (error instanceof BaerlyError) throw error;
|
|
1728
1816
|
throw new BaerlyError("SchemaError", `Failed to read request body: ${error instanceof Error ? error.message : String(error)}`);
|
|
1729
1817
|
}
|
|
1730
|
-
if (raw.length === 0) throw new BaerlyError("SchemaError", "Empty request body");
|
|
1818
|
+
if (raw.length === 0) throw new BaerlyError("SchemaError", "Empty request body", void 0, void 0, void 0, WRITE_BODY_SHAPE_RESOLUTION);
|
|
1731
1819
|
try {
|
|
1732
1820
|
return JSON.parse(raw);
|
|
1733
1821
|
} catch {
|
|
1734
|
-
throw new BaerlyError("SchemaError", "Invalid JSON in request body");
|
|
1822
|
+
throw new BaerlyError("SchemaError", "Invalid JSON in request body", void 0, void 0, void 0, WRITE_BODY_SHAPE_RESOLUTION);
|
|
1735
1823
|
}
|
|
1736
1824
|
}
|
|
1737
1825
|
//#endregion
|
|
1738
1826
|
export { longPollSince as a, listEventsSince as i, createRouter as n, Hono as o, mapError as r, MAX_BODY_BYTES as t };
|
|
1739
1827
|
|
|
1740
|
-
//# sourceMappingURL=http-
|
|
1828
|
+
//# sourceMappingURL=http-DxM9MflO.js.map
|