@gusto/baerly-storage 0.1.1 → 0.1.2
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 +3 -2
- package/dist/API.md +59 -7
- package/dist/{app-config-Dj_nGBfj.d.ts → app-config-C0Bbw_Z6.d.ts} +9 -9
- package/dist/app-config.d.ts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/baerly.js +10 -10
- package/dist/baerly.js.map +1 -1
- package/dist/bytes-BXdamO3L.js +11 -0
- package/dist/bytes-BXdamO3L.js.map +1 -0
- package/dist/{client-CC5yVs1S.d.ts → client-DYZfoZb9.d.ts} +3 -3
- package/dist/client-react.d.ts +3 -3
- package/dist/client.d.ts +3 -3
- package/dist/cloudflare.d.ts +31 -4
- package/dist/cloudflare.js +72 -6
- package/dist/cloudflare.js.map +1 -1
- package/dist/{config-Bsg8wgwo.js → config-DVfDGyw1.js} +82 -2
- package/dist/config-DVfDGyw1.js.map +1 -0
- package/dist/{context-Oj7ffwD-.js → context-DRZ3tZ5l.js} +3 -2
- package/dist/{context-Oj7ffwD-.js.map → context-DRZ3tZ5l.js.map} +1 -1
- package/dist/{cost-B1WiZxlf.js → cost-CQt1YRkA.js} +3 -4
- package/dist/{cost-B1WiZxlf.js.map → cost-CQt1YRkA.js.map} +1 -1
- package/dist/{current-json-BkatBzF7.js → current-json-C-EyJqs0.js} +107 -5
- package/dist/current-json-C-EyJqs0.js.map +1 -0
- package/dist/{db-aRMK_0R0.d.ts → db-BM3y2JQw.d.ts} +3 -3
- package/dist/{deploy-BB-wqbhf.js → deploy-CrAbfgCq.js} +2 -2
- package/dist/{deploy-BB-wqbhf.js.map → deploy-CrAbfgCq.js.map} +1 -1
- package/dist/dev-vite.d.ts +3 -3
- package/dist/dev-vite.js +3 -3
- package/dist/dev.d.ts +1 -1
- package/dist/dev.js +1 -1
- package/dist/{doctor-B8h9GCN9.js → doctor-Db-hzPmE.js} +144 -7
- package/dist/doctor-Db-hzPmE.js.map +1 -0
- package/dist/{dump-BHo_sIMZ.js → dump-BYA55NLP.js} +3 -4
- package/dist/{dump-BHo_sIMZ.js.map → dump-BYA55NLP.js.map} +1 -1
- package/dist/errors-DOdL95kK.js.map +1 -1
- package/dist/{export-Dz2PZKSR.js → export-Bhbz90-z.js} +4 -5
- package/dist/{export-Dz2PZKSR.js.map → export-Bhbz90-z.js.map} +1 -1
- package/dist/{fsck-DEz9lyCy.js → fsck-CPPZWt9p.js} +5 -8
- package/dist/fsck-CPPZWt9p.js.map +1 -0
- package/dist/{http-DeJEeUcO.js → http-Cw8p6y5b.js} +5 -5
- package/dist/{http-DeJEeUcO.js.map → http-Cw8p6y5b.js.map} +1 -1
- package/dist/http.d.ts +3 -3
- package/dist/http.js +1 -1
- package/dist/{index-m6pY8iRU.d.ts → index-C3JAH1Yo.d.ts} +14 -2
- package/dist/{index-5lX_5NxZ.d.ts → index-DSvwEUeF.d.ts} +63 -54
- package/dist/{index-DPaQhAro.d.ts → index-DwDTWPSU.d.ts} +2 -2
- package/dist/{index-spCBsIwm.d.ts → index-cUY-36AN.d.ts} +3 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -3
- package/dist/{indexes-BIH73Uv4.d.ts → indexes-DAu2AkTW.d.ts} +2 -2
- package/dist/{inspect-x02aFWnh.js → inspect-Bdbzvi-_.js} +5 -6
- package/dist/{inspect-x02aFWnh.js.map → inspect-Bdbzvi-_.js.map} +1 -1
- package/dist/maintenance-BRrThz8V.d.ts +449 -0
- package/dist/maintenance-BvOv6BMM.js +1295 -0
- package/dist/maintenance-BvOv6BMM.js.map +1 -0
- package/dist/maintenance-ClzBC1Vv.js +1895 -0
- package/dist/maintenance-ClzBC1Vv.js.map +1 -0
- package/dist/maintenance.d.ts +2 -323
- package/dist/maintenance.js +2 -2
- package/dist/node.d.ts +20 -79
- package/dist/node.js +2 -2
- package/dist/{observability-2IDYRuZK.js → observability-CpOiEN0k.js} +2 -2
- package/dist/{observability-2IDYRuZK.js.map → observability-CpOiEN0k.js.map} +1 -1
- package/dist/observability.d.ts +2 -2
- package/dist/observability.js +2 -2
- package/dist/{plan-Cs17VqjU.js → plan-DOTl21vq.js} +3 -4
- package/dist/{plan-Cs17VqjU.js.map → plan-DOTl21vq.js.map} +1 -1
- package/dist/{query-DcSbFLJt.js → query-BmiQy328.js} +58 -26
- package/dist/query-BmiQy328.js.map +1 -0
- package/dist/{rebuild-index-DwXM0WfA.js → rebuild-index-DC_nR6wP.js} +4 -5
- package/dist/{rebuild-index-DwXM0WfA.js.map → rebuild-index-DC_nR6wP.js.map} +1 -1
- package/dist/{restore-CbKVMMpm.js → restore-C6IcmLeA.js} +44 -120
- package/dist/restore-C6IcmLeA.js.map +1 -0
- package/dist/{log-walk-DIru96UT.js → snapshot-SS8USDUF.js} +187 -20
- package/dist/snapshot-SS8USDUF.js.map +1 -0
- package/dist/{src-Cr9C7_tT.js → src-DU1sCMlr.js} +315 -278
- package/dist/src-DU1sCMlr.js.map +1 -0
- package/dist/{src-n0Te1r98.js → src-QQ7jDeL2.js} +25 -6
- package/dist/src-QQ7jDeL2.js.map +1 -0
- package/dist/{src-Chafbw8r.js → src-zhEAmmF7.js} +35 -4
- package/dist/src-zhEAmmF7.js.map +1 -0
- package/dist/{bucket-uri-BrDEYvzy.js → subcommand-DZcHcsYp.js} +222 -22
- package/dist/subcommand-DZcHcsYp.js.map +1 -0
- package/dist/{usage-RVUQMLop.js → usage-CLjirdD-.js} +4 -4
- package/dist/{usage-RVUQMLop.js.map → usage-CLjirdD-.js.map} +1 -1
- package/dist/{validate-DhH1lO8I.js → validate-DCq_0DIn.js} +2 -2
- package/dist/validate-DCq_0DIn.js.map +1 -0
- package/package.json +13 -6
- package/dist/bucket-uri-BrDEYvzy.js.map +0 -1
- package/dist/config-Bsg8wgwo.js.map +0 -1
- package/dist/current-json-BkatBzF7.js.map +0 -1
- package/dist/doctor-B8h9GCN9.js.map +0 -1
- package/dist/fsck-DEz9lyCy.js.map +0 -1
- package/dist/indexes-BXn7a06a.js +0 -297
- package/dist/indexes-BXn7a06a.js.map +0 -1
- package/dist/log-walk-DIru96UT.js.map +0 -1
- package/dist/maintenance-Bn6ul9aV.js +0 -758
- package/dist/maintenance-Bn6ul9aV.js.map +0 -1
- package/dist/query-DcSbFLJt.js.map +0 -1
- package/dist/rebuild-index-C5gTXryd.js +0 -119
- package/dist/rebuild-index-C5gTXryd.js.map +0 -1
- package/dist/restore-CbKVMMpm.js.map +0 -1
- package/dist/snapshot-D7C4_FSl.js +0 -71
- package/dist/snapshot-D7C4_FSl.js.map +0 -1
- package/dist/snapshot-z_N9hpTe.js +0 -917
- package/dist/snapshot-z_N9hpTe.js.map +0 -1
- package/dist/src-Chafbw8r.js.map +0 -1
- package/dist/src-Cr9C7_tT.js.map +0 -1
- package/dist/src-n0Te1r98.js.map +0 -1
- package/dist/subcommand-BWs6K7zb.js +0 -110
- package/dist/subcommand-BWs6K7zb.js.map +0 -1
- package/dist/validate-DhH1lO8I.js.map +0 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { g as RATE_LIMIT_BACKOFF_MILLIS } from "./current-json-C-EyJqs0.js";
|
|
2
2
|
import { t as BaerlyError } from "./errors-DOdL95kK.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { r as
|
|
7
|
-
import { n as
|
|
8
|
-
import {
|
|
9
|
-
import { a as require_picocolors_browser, r as renderDevLanding } from "./src-n0Te1r98.js";
|
|
3
|
+
import { l as delay } from "./query-BmiQy328.js";
|
|
4
|
+
import { n as resolveVerifier, t as Db } from "./src-zhEAmmF7.js";
|
|
5
|
+
import { r as runWithContext, t as createObservabilityContext } from "./context-DRZ3tZ5l.js";
|
|
6
|
+
import { n as createRouter, o as Hono, r as mapError, t as MAX_BODY_BYTES } from "./http-Cw8p6y5b.js";
|
|
7
|
+
import { c as configureObservability, n as flushCanonicalLine, o as deriveOutcome, r as flushUnauthorizedAndRespond, t as observableStorage } from "./observability-CpOiEN0k.js";
|
|
8
|
+
import { a as require_picocolors_browser, r as renderDevLanding } from "./src-QQ7jDeL2.js";
|
|
10
9
|
import { readFile, stat } from "node:fs/promises";
|
|
11
10
|
import { extname, relative, resolve, sep } from "node:path";
|
|
12
11
|
import { STATUS_CODES, createServer } from "node:http";
|
|
@@ -3800,6 +3799,40 @@ const xmlVal = (obj, name) => {
|
|
|
3800
3799
|
if (typeof v !== "string" || v === "") return;
|
|
3801
3800
|
return decodeURIComponent(v.replace(/\+/g, " "));
|
|
3802
3801
|
};
|
|
3802
|
+
const rawXmlVal = (obj, name) => {
|
|
3803
|
+
const v = obj[name];
|
|
3804
|
+
return typeof v === "string" && v !== "" ? v : void 0;
|
|
3805
|
+
};
|
|
3806
|
+
/**
|
|
3807
|
+
* Parse an S3 `<Error><Code>…</Code><Message>…</Message></Error>`
|
|
3808
|
+
* body. Returns `undefined` when the body is not a recognizable S3
|
|
3809
|
+
* error document (empty, HTML, a success payload, or a DTD), so
|
|
3810
|
+
* callers can fall back to the raw response text. This never throws:
|
|
3811
|
+
* it runs on a path that is already reporting an error.
|
|
3812
|
+
*/
|
|
3813
|
+
const parseS3Error = (xml) => {
|
|
3814
|
+
if (!/<Error\b/i.test(xml) || /<!DOCTYPE\b/i.test(xml)) return;
|
|
3815
|
+
let result;
|
|
3816
|
+
try {
|
|
3817
|
+
result = xmlParser.parse(xml);
|
|
3818
|
+
} catch {
|
|
3819
|
+
return;
|
|
3820
|
+
}
|
|
3821
|
+
const root = result.Error;
|
|
3822
|
+
if (root === void 0) return;
|
|
3823
|
+
const code = rawXmlVal(root, "Code");
|
|
3824
|
+
const message = rawXmlVal(root, "Message");
|
|
3825
|
+
if (code === void 0 && message === void 0) return;
|
|
3826
|
+
return {
|
|
3827
|
+
...code !== void 0 && { Code: code },
|
|
3828
|
+
...message !== void 0 && { Message: message }
|
|
3829
|
+
};
|
|
3830
|
+
};
|
|
3831
|
+
const parseLastModified = (lm) => {
|
|
3832
|
+
if (lm === void 0) return;
|
|
3833
|
+
const d = new Date(lm);
|
|
3834
|
+
return Number.isNaN(d.getTime()) ? void 0 : d;
|
|
3835
|
+
};
|
|
3803
3836
|
const parseListObjectsV2CommandOutput = (xml) => {
|
|
3804
3837
|
if (/<!DOCTYPE\b/i.test(xml)) throw new BaerlyError("InvalidResponse", "DTD not allowed in S3 XML responses");
|
|
3805
3838
|
let result;
|
|
@@ -3811,14 +3844,13 @@ const parseListObjectsV2CommandOutput = (xml) => {
|
|
|
3811
3844
|
const root = result.ListBucketResult ?? {};
|
|
3812
3845
|
return {
|
|
3813
3846
|
Contents: (root["Contents"] ?? []).map((content) => {
|
|
3814
|
-
const lm = xmlVal(content, "LastModified");
|
|
3815
3847
|
return {
|
|
3816
|
-
ETag:
|
|
3848
|
+
ETag: rawXmlVal(content, "ETag"),
|
|
3817
3849
|
Key: xmlVal(content, "Key"),
|
|
3818
|
-
LastModified:
|
|
3850
|
+
LastModified: parseLastModified(rawXmlVal(content, "LastModified"))
|
|
3819
3851
|
};
|
|
3820
3852
|
}),
|
|
3821
|
-
NextContinuationToken:
|
|
3853
|
+
NextContinuationToken: rawXmlVal(root, "NextContinuationToken")
|
|
3822
3854
|
};
|
|
3823
3855
|
};
|
|
3824
3856
|
//#endregion
|
|
@@ -3869,6 +3901,14 @@ const retryAfterCause = (res) => {
|
|
|
3869
3901
|
const hint = parseRetryAfter(res.headers.get("Retry-After"));
|
|
3870
3902
|
return hint !== void 0 ? { retryAfterSeconds: hint } : {};
|
|
3871
3903
|
};
|
|
3904
|
+
const s3ErrorDetail = (status, body) => {
|
|
3905
|
+
const parsed = parseS3Error(body);
|
|
3906
|
+
if (parsed !== void 0) {
|
|
3907
|
+
const code = parsed.Code ?? "UnknownError";
|
|
3908
|
+
return parsed.Message !== void 0 ? `${status} ${code}: ${parsed.Message}` : `${status} ${code}`;
|
|
3909
|
+
}
|
|
3910
|
+
return `${status} ${body}`;
|
|
3911
|
+
};
|
|
3872
3912
|
const retry = async (fn, { retries = 8, backoffMs = 100, maxDelayMs = 1e4 } = {}) => {
|
|
3873
3913
|
let wait = backoffMs;
|
|
3874
3914
|
for (let attempt = 0; attempt <= retries; attempt++) try {
|
|
@@ -3961,7 +4001,7 @@ var S3HttpStorage = class {
|
|
|
3961
4001
|
status: res.status,
|
|
3962
4002
|
...retryAfterCause(res)
|
|
3963
4003
|
});
|
|
3964
|
-
throw new BaerlyError("InvalidResponse", `GET ${key}: ${res.status
|
|
4004
|
+
throw new BaerlyError("InvalidResponse", `GET ${key}: ${s3ErrorDetail(res.status, await res.text())}`);
|
|
3965
4005
|
}
|
|
3966
4006
|
});
|
|
3967
4007
|
}
|
|
@@ -3986,7 +4026,7 @@ var S3HttpStorage = class {
|
|
|
3986
4026
|
status: res.status,
|
|
3987
4027
|
...retryAfterCause(res)
|
|
3988
4028
|
});
|
|
3989
|
-
if (res.status !== 200 && res.status !== 204) throw new BaerlyError("InvalidResponse", `PUT ${key}: ${res.status
|
|
4029
|
+
if (res.status !== 200 && res.status !== 204) throw new BaerlyError("InvalidResponse", `PUT ${key}: ${s3ErrorDetail(res.status, await res.text())}`);
|
|
3990
4030
|
const etag = res.headers.get("ETag");
|
|
3991
4031
|
if (etag === null) throw new BaerlyError("InvalidResponse", `PUT ${key}: missing ETag`);
|
|
3992
4032
|
const dateStr = res.headers.get("Date");
|
|
@@ -4022,6 +4062,7 @@ var S3HttpStorage = class {
|
|
|
4022
4062
|
const params = new URLSearchParams();
|
|
4023
4063
|
params.set("list-type", "2");
|
|
4024
4064
|
params.set("prefix", prefix);
|
|
4065
|
+
params.set("encoding-type", "url");
|
|
4025
4066
|
if (continuationToken !== void 0) params.set("continuation-token", continuationToken);
|
|
4026
4067
|
else if (startAfter !== "") params.set("start-after", startAfter);
|
|
4027
4068
|
if (opts?.maxKeys !== void 0) {
|
|
@@ -4050,7 +4091,7 @@ var S3HttpStorage = class {
|
|
|
4050
4091
|
status: res.status,
|
|
4051
4092
|
...retryAfterCause(res)
|
|
4052
4093
|
});
|
|
4053
|
-
throw new BaerlyError("InvalidResponse", `LIST ${prefix}: ${res.status
|
|
4094
|
+
throw new BaerlyError("InvalidResponse", `LIST ${prefix}: ${s3ErrorDetail(res.status, await res.text())}`);
|
|
4054
4095
|
});
|
|
4055
4096
|
if (outcome.kind === "ok") {
|
|
4056
4097
|
parsed = parseListObjectsV2CommandOutput(outcome.body);
|
|
@@ -4080,229 +4121,6 @@ var S3HttpStorage = class {
|
|
|
4080
4121
|
}
|
|
4081
4122
|
};
|
|
4082
4123
|
//#endregion
|
|
4083
|
-
//#region packages/adapter-node/src/logger-pretty.ts
|
|
4084
|
-
var import_picocolors_browser = require_picocolors_browser();
|
|
4085
|
-
/**
|
|
4086
|
-
* Metric keys the pretty sink reads off the canonical-line record.
|
|
4087
|
-
* These names match `RequestScopedMetricsRecorder.summarize()` output
|
|
4088
|
-
* in `packages/server/src/observability/recorder.ts`. If the recorder
|
|
4089
|
-
* renames a key, update both sides here.
|
|
4090
|
-
*/
|
|
4091
|
-
const CANONICAL_KEYS = {
|
|
4092
|
-
classA: "db.storage.class_a_ops_total",
|
|
4093
|
-
classB: "db.storage.class_b_ops_total",
|
|
4094
|
-
wamp: "db.write.class_a_ops_per_logical_write_sum",
|
|
4095
|
-
put412: "db.r2.put.412_total",
|
|
4096
|
-
put429: "db.r2.put.429_total",
|
|
4097
|
-
cacheStatus: "cache_status"
|
|
4098
|
-
};
|
|
4099
|
-
/**
|
|
4100
|
-
* Fixed-width column sizes for the pretty sink's HTTP line.
|
|
4101
|
-
* Local to the renderer — these are presentation defaults, not
|
|
4102
|
-
* protocol invariants, so they don't belong in `@baerly/protocol`.
|
|
4103
|
-
*/
|
|
4104
|
-
const METHOD_W = 6;
|
|
4105
|
-
const PATH_W = 28;
|
|
4106
|
-
const pickProp = (props, key) => Object.prototype.hasOwnProperty.call(props, key) ? props[key] : void 0;
|
|
4107
|
-
const numProp = (props, key) => {
|
|
4108
|
-
const v = pickProp(props, key);
|
|
4109
|
-
return typeof v === "number" ? v : void 0;
|
|
4110
|
-
};
|
|
4111
|
-
const colorStatus = (statusStr, status, plain, pc) => {
|
|
4112
|
-
if (plain || status === void 0) return statusStr;
|
|
4113
|
-
if (status >= 500) return pc.red(statusStr);
|
|
4114
|
-
if (status >= 400) return pc.yellow(statusStr);
|
|
4115
|
-
if (status >= 300) return pc.cyan(statusStr);
|
|
4116
|
-
return pc.dim(statusStr);
|
|
4117
|
-
};
|
|
4118
|
-
const renderCanonical = (record, pc, plain) => {
|
|
4119
|
-
const props = record.properties;
|
|
4120
|
-
const ts = new Date(record.timestamp).toISOString().slice(11, 19);
|
|
4121
|
-
const reqId = String(pickProp(props, "request_id") ?? "").slice(0, 8);
|
|
4122
|
-
const duration = numProp(props, "duration_ms") ?? 0;
|
|
4123
|
-
const durationStr = `${Math.round(duration)}ms`.padStart(5);
|
|
4124
|
-
const status = numProp(props, "status");
|
|
4125
|
-
const method = typeof pickProp(props, "method") === "string" ? String(pickProp(props, "method")) : "";
|
|
4126
|
-
const path = typeof pickProp(props, "path") === "string" ? String(pickProp(props, "path")) : "";
|
|
4127
|
-
const prefix = `${method.padEnd(METHOD_W)}${path.length > PATH_W ? `${path.slice(0, PATH_W - 1)}…` : path.padEnd(PATH_W)} ${colorStatus(status === void 0 ? " " : String(status), status, plain, pc)} ${durationStr}`;
|
|
4128
|
-
const tail = [];
|
|
4129
|
-
if (reqId) tail.push(`req=${reqId}`);
|
|
4130
|
-
const classA = numProp(props, CANONICAL_KEYS.classA);
|
|
4131
|
-
const classB = numProp(props, CANONICAL_KEYS.classB);
|
|
4132
|
-
if (classA !== void 0) tail.push(`class_a=${classA}`);
|
|
4133
|
-
if (classB !== void 0) tail.push(`class_b=${classB}`);
|
|
4134
|
-
const wamp = numProp(props, CANONICAL_KEYS.wamp);
|
|
4135
|
-
if (wamp !== void 0) tail.push(`wamp=${wamp}`);
|
|
4136
|
-
const c412 = numProp(props, CANONICAL_KEYS.put412);
|
|
4137
|
-
if (c412 !== void 0 && c412 > 0) tail.push(`412=${c412}`);
|
|
4138
|
-
const c429 = numProp(props, CANONICAL_KEYS.put429);
|
|
4139
|
-
if (c429 !== void 0 && c429 > 0) tail.push(`429=${c429}`);
|
|
4140
|
-
const cacheStatus = pickProp(props, CANONICAL_KEYS.cacheStatus);
|
|
4141
|
-
if (typeof cacheStatus === "string") tail.push(`cache=${cacheStatus}`);
|
|
4142
|
-
if (status !== void 0 && status >= 400) {
|
|
4143
|
-
const outcome = pickProp(props, "outcome");
|
|
4144
|
-
if (typeof outcome === "string") tail.push(`outcome=${outcome}`);
|
|
4145
|
-
}
|
|
4146
|
-
const tailStr = tail.length ? ` ${tail.join(" ")}` : "";
|
|
4147
|
-
return `${plain ? `${ts} ` : `${pc.dim(ts)} `}${prefix}${tailStr}`;
|
|
4148
|
-
};
|
|
4149
|
-
const isCanonicalRecord = (record) => record.message.length === 1 && record.message[0] === "canonical";
|
|
4150
|
-
const isPlainEnv = () => {
|
|
4151
|
-
const proc = globalThis.process;
|
|
4152
|
-
return proc?.stdout?.isTTY !== true || proc?.env?.["CI"] !== void 0;
|
|
4153
|
-
};
|
|
4154
|
-
/**
|
|
4155
|
-
* Built-in pretty sink. Renders canonical-line records (the
|
|
4156
|
-
* single-emit/unit-of-work records produced by `flushCanonicalLine`
|
|
4157
|
-
* in `@baerly/server/observability`) in a column-aligned cost-aware
|
|
4158
|
-
* format intended for local dev; falls back to a generic
|
|
4159
|
-
* `<ts> <LEVEL> <category> <msg> <jsonProps>` layout for every
|
|
4160
|
-
* other record (warn-line `verifier_rejected`, debug storage
|
|
4161
|
-
* emits, etc.).
|
|
4162
|
-
*
|
|
4163
|
-
* Color is enabled when stderr is a TTY and `CI` is unset. Under
|
|
4164
|
-
* vitest, stderr is non-TTY so color is off — tests can assert
|
|
4165
|
-
* substring matches without stripping ANSI escapes.
|
|
4166
|
-
*/
|
|
4167
|
-
const prettyConsoleSink = () => {
|
|
4168
|
-
const plain = isPlainEnv();
|
|
4169
|
-
const pc = (0, import_picocolors_browser.createColors)(!plain);
|
|
4170
|
-
return (record) => {
|
|
4171
|
-
if (isCanonicalRecord(record)) {
|
|
4172
|
-
console.log(renderCanonical(record, pc, plain));
|
|
4173
|
-
return;
|
|
4174
|
-
}
|
|
4175
|
-
const ts = new Date(record.timestamp).toISOString();
|
|
4176
|
-
const cat = record.category.join(".");
|
|
4177
|
-
const msg = record.message.map((m) => typeof m === "string" ? m : JSON.stringify(m)).join("");
|
|
4178
|
-
const props = Object.keys(record.properties).length ? ` ${JSON.stringify(record.properties)}` : "";
|
|
4179
|
-
console.log(`${ts} ${record.level.toUpperCase()} ${cat} ${msg}${props}`);
|
|
4180
|
-
};
|
|
4181
|
-
};
|
|
4182
|
-
//#endregion
|
|
4183
|
-
//#region packages/adapter-node/src/server.ts
|
|
4184
|
-
/**
|
|
4185
|
-
* Build a `(req: Request) => Promise<Response>` handler that runs the
|
|
4186
|
-
* baerly `/v1/*` cascade: healthz short-circuit → observability context
|
|
4187
|
-
* → verifier → `Db.create` → `createRouter({db}).fetch(req)` →
|
|
4188
|
-
* canonical-line flush. The handler is host-agnostic; mount it under
|
|
4189
|
-
* `/v1/*` in your Fetch framework.
|
|
4190
|
-
*
|
|
4191
|
-
* Non-`/v1/*` paths fall through to the Hono router, which renders the
|
|
4192
|
-
* kernel's 404 envelope. To compose static-asset or dev-landing
|
|
4193
|
-
* handlers, dispatch those upstream of this factory — see the
|
|
4194
|
-
* internal Hono-app factory in `./app.ts` for the production composition.
|
|
4195
|
-
*
|
|
4196
|
-
* @internal — public consumers reach this via `baerlyNode` from
|
|
4197
|
-
* `./baerly-node.ts`. Exported for intra-package re-use and direct unit
|
|
4198
|
-
* coverage in `server.test.ts`.
|
|
4199
|
-
*/
|
|
4200
|
-
function createFetchHandler(opts) {
|
|
4201
|
-
configureObservability(resolveDefaultSink(opts.observability ?? {}));
|
|
4202
|
-
const wrappedStorage = observableStorage(opts.storage);
|
|
4203
|
-
return async (request) => {
|
|
4204
|
-
const path = new URL(request.url).pathname;
|
|
4205
|
-
if (request.method === "GET" && path === "/v1/healthz") return new Response(JSON.stringify({ ok: true }), {
|
|
4206
|
-
status: 200,
|
|
4207
|
-
headers: { "content-type": "application/json" }
|
|
4208
|
-
});
|
|
4209
|
-
const obsCtx = createObservabilityContext({ request_id: request.headers.get("x-request-id") ?? crypto.randomUUID() });
|
|
4210
|
-
const result = await opts.verifier(request);
|
|
4211
|
-
if (result === null) return await runWithContext(obsCtx, async () => flushUnauthorizedAndRespond(obsCtx, request));
|
|
4212
|
-
return await runWithContext(obsCtx, async () => {
|
|
4213
|
-
let outboundStatus = 500;
|
|
4214
|
-
let caughtError;
|
|
4215
|
-
let response;
|
|
4216
|
-
try {
|
|
4217
|
-
response = await createRouter({
|
|
4218
|
-
db: Db.create({
|
|
4219
|
-
storage: wrappedStorage,
|
|
4220
|
-
app: opts.app,
|
|
4221
|
-
tenant: result.tenantPrefix,
|
|
4222
|
-
config: opts.config
|
|
4223
|
-
}),
|
|
4224
|
-
...opts.sinceTimeoutMs !== void 0 && { sinceTimeoutMs: opts.sinceTimeoutMs },
|
|
4225
|
-
...opts.sincePollIntervalMs !== void 0 && { sincePollIntervalMs: opts.sincePollIntervalMs }
|
|
4226
|
-
}).fetch(request);
|
|
4227
|
-
outboundStatus = response.status;
|
|
4228
|
-
} catch (error) {
|
|
4229
|
-
caughtError = error;
|
|
4230
|
-
const { status, envelope } = mapError(error);
|
|
4231
|
-
outboundStatus = status;
|
|
4232
|
-
response = new Response(JSON.stringify(envelope), {
|
|
4233
|
-
status,
|
|
4234
|
-
headers: { "content-type": "application/json" }
|
|
4235
|
-
});
|
|
4236
|
-
} finally {
|
|
4237
|
-
flushCanonicalLine(obsCtx, obsCtx.recorder, {
|
|
4238
|
-
unit: "http",
|
|
4239
|
-
status: outboundStatus,
|
|
4240
|
-
outcome: deriveOutcome(request.method, outboundStatus, caughtError),
|
|
4241
|
-
...caughtError !== void 0 && { error: caughtError },
|
|
4242
|
-
extra: {
|
|
4243
|
-
method: request.method,
|
|
4244
|
-
path
|
|
4245
|
-
}
|
|
4246
|
-
});
|
|
4247
|
-
}
|
|
4248
|
-
return response;
|
|
4249
|
-
});
|
|
4250
|
-
};
|
|
4251
|
-
}
|
|
4252
|
-
/**
|
|
4253
|
-
* Run one pass of compaction + GC for one collection. Node hosts have
|
|
4254
|
-
* no subrequest cap, so this uses the engine defaults (unbounded) —
|
|
4255
|
-
* a single pass folds the entire live tail and sweeps every aged-out
|
|
4256
|
-
* candidate.
|
|
4257
|
-
*
|
|
4258
|
-
* Pair with `node-cron`, systemd timers, or k8s CronJobs — this
|
|
4259
|
-
* function is a single-shot callable that does not loop. Errors
|
|
4260
|
-
* propagate; the caller decides retry semantics.
|
|
4261
|
-
*
|
|
4262
|
-
* `compact()` and `runGc()` are each CAS-protected single-attempts:
|
|
4263
|
-
* a crash or restart between phases is safe because the next tick
|
|
4264
|
-
* picks up where the previous one left off.
|
|
4265
|
-
*
|
|
4266
|
-
* @example
|
|
4267
|
-
* ```ts
|
|
4268
|
-
* import cron from "node-cron";
|
|
4269
|
-
* import { runMaintenanceTick } from "@gusto/baerly-storage/node";
|
|
4270
|
-
*
|
|
4271
|
-
* cron.schedule("0 * * * *", async () => { // hourly
|
|
4272
|
-
* await runMaintenanceTick({ storage, currentJsonKey: "..." });
|
|
4273
|
-
* });
|
|
4274
|
-
* ```
|
|
4275
|
-
*/
|
|
4276
|
-
const runMaintenanceTick = async (opts) => {
|
|
4277
|
-
await runScheduledMaintenance({
|
|
4278
|
-
storage: observableStorage(opts.storage),
|
|
4279
|
-
currentJsonKey: opts.currentJsonKey
|
|
4280
|
-
}, { ...opts.signal !== void 0 && { signal: opts.signal } });
|
|
4281
|
-
};
|
|
4282
|
-
/**
|
|
4283
|
-
* Auto-pick the default sink when the caller passed an
|
|
4284
|
-
* {@link ObservabilityConfig} without a `sink` field. On a TTY
|
|
4285
|
-
* (developer terminals) we prefer pretty output; otherwise JSON
|
|
4286
|
-
* (production hosts pipe stdout to a log aggregator).
|
|
4287
|
-
*
|
|
4288
|
-
* Returns a new config with `sink` defaulted; if the caller already
|
|
4289
|
-
* supplied a `sink` (function or shorthand string) we pass the
|
|
4290
|
-
* config through verbatim. Either way the caller's `level` (when
|
|
4291
|
-
* set) reaches LogTape unchanged.
|
|
4292
|
-
*
|
|
4293
|
-
* Exported for the test suite — the TTY check is otherwise a pure
|
|
4294
|
-
* read of `process.stdout.isTTY` and a default lookup, neither
|
|
4295
|
-
* worth a black-box round-trip.
|
|
4296
|
-
*/
|
|
4297
|
-
const resolveDefaultSink = (config) => {
|
|
4298
|
-
if (config.sink !== void 0) return config;
|
|
4299
|
-
const isTty = Boolean(process.stdout.isTTY);
|
|
4300
|
-
return {
|
|
4301
|
-
...config,
|
|
4302
|
-
sink: isTty ? prettyConsoleSink() : "console-json"
|
|
4303
|
-
};
|
|
4304
|
-
};
|
|
4305
|
-
//#endregion
|
|
4306
4124
|
//#region node_modules/.pnpm/aws4fetch@1.0.20/node_modules/aws4fetch/dist/aws4fetch.esm.mjs
|
|
4307
4125
|
/**
|
|
4308
4126
|
* @license MIT <https://opensource.org/licenses/MIT>
|
|
@@ -5993,6 +5811,253 @@ async function statFile(target) {
|
|
|
5993
5811
|
}
|
|
5994
5812
|
}
|
|
5995
5813
|
//#endregion
|
|
5814
|
+
//#region packages/adapter-node/src/logger-pretty.ts
|
|
5815
|
+
var import_picocolors_browser = require_picocolors_browser();
|
|
5816
|
+
/**
|
|
5817
|
+
* Metric keys the pretty sink reads off the canonical-line record.
|
|
5818
|
+
* These names match `RequestScopedMetricsRecorder.summarize()` output
|
|
5819
|
+
* in `packages/server/src/observability/recorder.ts`. If the recorder
|
|
5820
|
+
* renames a key, update both sides here.
|
|
5821
|
+
*/
|
|
5822
|
+
const CANONICAL_KEYS = {
|
|
5823
|
+
classA: "db.storage.class_a_ops_total",
|
|
5824
|
+
classB: "db.storage.class_b_ops_total",
|
|
5825
|
+
wamp: "db.write.class_a_ops_per_logical_write_sum",
|
|
5826
|
+
put412: "db.r2.put.412_total",
|
|
5827
|
+
put429: "db.r2.put.429_total",
|
|
5828
|
+
cacheStatus: "cache_status"
|
|
5829
|
+
};
|
|
5830
|
+
/**
|
|
5831
|
+
* Fixed-width column sizes for the pretty sink's HTTP line.
|
|
5832
|
+
* Local to the renderer — these are presentation defaults, not
|
|
5833
|
+
* protocol invariants, so they don't belong in `@baerly/protocol`.
|
|
5834
|
+
*/
|
|
5835
|
+
const METHOD_W = 6;
|
|
5836
|
+
const PATH_W = 28;
|
|
5837
|
+
const pickProp = (props, key) => Object.prototype.hasOwnProperty.call(props, key) ? props[key] : void 0;
|
|
5838
|
+
const numProp = (props, key) => {
|
|
5839
|
+
const v = pickProp(props, key);
|
|
5840
|
+
return typeof v === "number" ? v : void 0;
|
|
5841
|
+
};
|
|
5842
|
+
const colorStatus = (statusStr, status, plain, pc) => {
|
|
5843
|
+
if (plain || status === void 0) return statusStr;
|
|
5844
|
+
if (status >= 500) return pc.red(statusStr);
|
|
5845
|
+
if (status >= 400) return pc.yellow(statusStr);
|
|
5846
|
+
if (status >= 300) return pc.cyan(statusStr);
|
|
5847
|
+
return pc.dim(statusStr);
|
|
5848
|
+
};
|
|
5849
|
+
const renderCanonical = (record, pc, plain) => {
|
|
5850
|
+
const props = record.properties;
|
|
5851
|
+
const ts = new Date(record.timestamp).toISOString().slice(11, 19);
|
|
5852
|
+
const reqId = String(pickProp(props, "request_id") ?? "").slice(0, 8);
|
|
5853
|
+
const duration = numProp(props, "duration_ms") ?? 0;
|
|
5854
|
+
const durationStr = `${Math.round(duration)}ms`.padStart(5);
|
|
5855
|
+
const status = numProp(props, "status");
|
|
5856
|
+
const method = typeof pickProp(props, "method") === "string" ? String(pickProp(props, "method")) : "";
|
|
5857
|
+
const path = typeof pickProp(props, "path") === "string" ? String(pickProp(props, "path")) : "";
|
|
5858
|
+
const prefix = `${method.padEnd(METHOD_W)}${path.length > PATH_W ? `${path.slice(0, PATH_W - 1)}…` : path.padEnd(PATH_W)} ${colorStatus(status === void 0 ? " " : String(status), status, plain, pc)} ${durationStr}`;
|
|
5859
|
+
const tail = [];
|
|
5860
|
+
if (reqId) tail.push(`req=${reqId}`);
|
|
5861
|
+
const classA = numProp(props, CANONICAL_KEYS.classA);
|
|
5862
|
+
const classB = numProp(props, CANONICAL_KEYS.classB);
|
|
5863
|
+
if (classA !== void 0) tail.push(`class_a=${classA}`);
|
|
5864
|
+
if (classB !== void 0) tail.push(`class_b=${classB}`);
|
|
5865
|
+
const wamp = numProp(props, CANONICAL_KEYS.wamp);
|
|
5866
|
+
if (wamp !== void 0) tail.push(`wamp=${wamp}`);
|
|
5867
|
+
const c412 = numProp(props, CANONICAL_KEYS.put412);
|
|
5868
|
+
if (c412 !== void 0 && c412 > 0) tail.push(`412=${c412}`);
|
|
5869
|
+
const c429 = numProp(props, CANONICAL_KEYS.put429);
|
|
5870
|
+
if (c429 !== void 0 && c429 > 0) tail.push(`429=${c429}`);
|
|
5871
|
+
const cacheStatus = pickProp(props, CANONICAL_KEYS.cacheStatus);
|
|
5872
|
+
if (typeof cacheStatus === "string") tail.push(`cache=${cacheStatus}`);
|
|
5873
|
+
if (status !== void 0 && status >= 400) {
|
|
5874
|
+
const outcome = pickProp(props, "outcome");
|
|
5875
|
+
if (typeof outcome === "string") tail.push(`outcome=${outcome}`);
|
|
5876
|
+
}
|
|
5877
|
+
const tailStr = tail.length ? ` ${tail.join(" ")}` : "";
|
|
5878
|
+
return `${plain ? `${ts} ` : `${pc.dim(ts)} `}${prefix}${tailStr}`;
|
|
5879
|
+
};
|
|
5880
|
+
const isCanonicalRecord = (record) => record.message.length === 1 && record.message[0] === "canonical";
|
|
5881
|
+
const isPlainEnv = () => {
|
|
5882
|
+
const proc = globalThis.process;
|
|
5883
|
+
return proc?.stdout?.isTTY !== true || proc?.env?.["CI"] !== void 0;
|
|
5884
|
+
};
|
|
5885
|
+
/**
|
|
5886
|
+
* Built-in pretty sink. Renders canonical-line records (the
|
|
5887
|
+
* single-emit/unit-of-work records produced by `flushCanonicalLine`
|
|
5888
|
+
* in `@baerly/server/observability`) in a column-aligned cost-aware
|
|
5889
|
+
* format intended for local dev; falls back to a generic
|
|
5890
|
+
* `<ts> <LEVEL> <category> <msg> <jsonProps>` layout for every
|
|
5891
|
+
* other record (warn-line `verifier_rejected`, debug storage
|
|
5892
|
+
* emits, etc.).
|
|
5893
|
+
*
|
|
5894
|
+
* Color is enabled when stderr is a TTY and `CI` is unset. Under
|
|
5895
|
+
* vitest, stderr is non-TTY so color is off — tests can assert
|
|
5896
|
+
* substring matches without stripping ANSI escapes.
|
|
5897
|
+
*/
|
|
5898
|
+
const prettyConsoleSink = () => {
|
|
5899
|
+
const plain = isPlainEnv();
|
|
5900
|
+
const pc = (0, import_picocolors_browser.createColors)(!plain);
|
|
5901
|
+
return (record) => {
|
|
5902
|
+
if (isCanonicalRecord(record)) {
|
|
5903
|
+
console.log(renderCanonical(record, pc, plain));
|
|
5904
|
+
return;
|
|
5905
|
+
}
|
|
5906
|
+
const ts = new Date(record.timestamp).toISOString();
|
|
5907
|
+
const cat = record.category.join(".");
|
|
5908
|
+
const msg = record.message.map((m) => typeof m === "string" ? m : JSON.stringify(m)).join("");
|
|
5909
|
+
const props = Object.keys(record.properties).length ? ` ${JSON.stringify(record.properties)}` : "";
|
|
5910
|
+
console.log(`${ts} ${record.level.toUpperCase()} ${cat} ${msg}${props}`);
|
|
5911
|
+
};
|
|
5912
|
+
};
|
|
5913
|
+
//#endregion
|
|
5914
|
+
//#region packages/adapter-node/src/server.ts
|
|
5915
|
+
/**
|
|
5916
|
+
* Assemble the per-request {@link MaintenanceDispatch} for a Node host.
|
|
5917
|
+
*
|
|
5918
|
+
* baerly maintains IN-BAND: the writer reads
|
|
5919
|
+
* `getCurrentContext()?.maintenance` at its post-CAS dispatch point and
|
|
5920
|
+
* runs one bounded compact + GC slice on the (rare) write that crosses a
|
|
5921
|
+
* maintenance trigger. Reads stay pure — they never tick. There is no
|
|
5922
|
+
* `setInterval`, no cron, no operator-installed scheduler: the kernel
|
|
5923
|
+
* maintains itself on a bare bucket with zero operator infrastructure.
|
|
5924
|
+
*
|
|
5925
|
+
* On Node v1 maintenance runs INLINE on the commit path (no
|
|
5926
|
+
* `dispatch` override — serverful Node has no `waitUntil`, and inline is
|
|
5927
|
+
* deterministic + correct here), so this returns no `dispatch` field;
|
|
5928
|
+
* the writer falls back to its inline-awaited default dispatch.
|
|
5929
|
+
*
|
|
5930
|
+
* The caps (`options`) are a MODERATE multiple of the CF-free defaults —
|
|
5931
|
+
* Node has no Cloudflare subrequest wall, but because v1 runs inline the
|
|
5932
|
+
* per-pass work is still BOUNDED by worst-case single-write added
|
|
5933
|
+
* latency, not unbounded. We thread `phasesPerTick: "both"` (a capable
|
|
5934
|
+
* host can fold AND GC in one tick) plus the Node-tier `WRITE_TICK_*`
|
|
5935
|
+
* overrides from `@baerly/protocol`'s `NODE_MAINTENANCE_*` constants
|
|
5936
|
+
* (10× CF-free, with a shorter GC interval so the sweep budget keeps up).
|
|
5937
|
+
*
|
|
5938
|
+
* The two ops-plane env vars are read here (per call) so a `vi.stubEnv`
|
|
5939
|
+
* in tests — and a real process env in production — is observed:
|
|
5940
|
+
*
|
|
5941
|
+
* - `BAERLY_MAINTENANCE_MAX_FOLD_BYTES` → `maxFoldBytes` (the snapshot
|
|
5942
|
+
* ceiling `C`). Parsed as a number; ignored when unset / NaN.
|
|
5943
|
+
* - `BAERLY_MAINTENANCE_DISABLE` → `disabled` (kill switch). Truthy
|
|
5944
|
+
* when set to a non-empty value other than `"0"` / `"false"`.
|
|
5945
|
+
*
|
|
5946
|
+
* `readEnv` defaults to `process.env`; the parameter exists for direct
|
|
5947
|
+
* unit coverage.
|
|
5948
|
+
*/
|
|
5949
|
+
const nodeMaintenanceDispatch = (readEnv = (k) => process.env[k]) => {
|
|
5950
|
+
const rawFoldBytes = readEnv("BAERLY_MAINTENANCE_MAX_FOLD_BYTES");
|
|
5951
|
+
const parsedFoldBytes = rawFoldBytes !== void 0 && rawFoldBytes !== "" ? Number(rawFoldBytes) : NaN;
|
|
5952
|
+
const maxFoldBytes = Number.isFinite(parsedFoldBytes) ? parsedFoldBytes : void 0;
|
|
5953
|
+
const rawDisable = readEnv("BAERLY_MAINTENANCE_DISABLE");
|
|
5954
|
+
return {
|
|
5955
|
+
...rawDisable !== void 0 && rawDisable !== "" && rawDisable !== "0" && rawDisable.toLowerCase() !== "false" && { disabled: true },
|
|
5956
|
+
...maxFoldBytes !== void 0 && { maxFoldBytes },
|
|
5957
|
+
options: {
|
|
5958
|
+
phasesPerTick: "both",
|
|
5959
|
+
maxFoldEntriesPerPass: 200,
|
|
5960
|
+
gcMaxMarks: 200,
|
|
5961
|
+
gcMaxSweeps: 100,
|
|
5962
|
+
gcInterval: 2
|
|
5963
|
+
}
|
|
5964
|
+
};
|
|
5965
|
+
};
|
|
5966
|
+
/**
|
|
5967
|
+
* Build a `(req: Request) => Promise<Response>` handler that runs the
|
|
5968
|
+
* baerly `/v1/*` cascade: healthz short-circuit → observability context
|
|
5969
|
+
* → verifier → `Db.create` → `createRouter({db}).fetch(req)` →
|
|
5970
|
+
* canonical-line flush. The handler is host-agnostic; mount it under
|
|
5971
|
+
* `/v1/*` in your Fetch framework.
|
|
5972
|
+
*
|
|
5973
|
+
* Non-`/v1/*` paths fall through to the Hono router, which renders the
|
|
5974
|
+
* kernel's 404 envelope. To compose static-asset or dev-landing
|
|
5975
|
+
* handlers, dispatch those upstream of this factory — see the
|
|
5976
|
+
* internal Hono-app factory in `./app.ts` for the production composition.
|
|
5977
|
+
*
|
|
5978
|
+
* @internal — public consumers reach this via `baerlyNode` from
|
|
5979
|
+
* `./baerly-node.ts`. Exported for intra-package re-use and direct unit
|
|
5980
|
+
* coverage in `server.test.ts`.
|
|
5981
|
+
*/
|
|
5982
|
+
function createFetchHandler(opts) {
|
|
5983
|
+
configureObservability(resolveDefaultSink(opts.observability ?? {}));
|
|
5984
|
+
const wrappedStorage = observableStorage(opts.storage);
|
|
5985
|
+
return async (request) => {
|
|
5986
|
+
const path = new URL(request.url).pathname;
|
|
5987
|
+
if (request.method === "GET" && path === "/v1/healthz") return new Response(JSON.stringify({ ok: true }), {
|
|
5988
|
+
status: 200,
|
|
5989
|
+
headers: { "content-type": "application/json" }
|
|
5990
|
+
});
|
|
5991
|
+
const obsCtx = createObservabilityContext({
|
|
5992
|
+
request_id: request.headers.get("x-request-id") ?? crypto.randomUUID(),
|
|
5993
|
+
maintenance: nodeMaintenanceDispatch()
|
|
5994
|
+
});
|
|
5995
|
+
const result = await opts.verifier(request);
|
|
5996
|
+
if (result === null) return await runWithContext(obsCtx, async () => flushUnauthorizedAndRespond(obsCtx, request));
|
|
5997
|
+
return await runWithContext(obsCtx, async () => {
|
|
5998
|
+
let outboundStatus = 500;
|
|
5999
|
+
let caughtError;
|
|
6000
|
+
let response;
|
|
6001
|
+
try {
|
|
6002
|
+
response = await createRouter({
|
|
6003
|
+
db: Db.create({
|
|
6004
|
+
storage: wrappedStorage,
|
|
6005
|
+
app: opts.app,
|
|
6006
|
+
tenant: result.tenantPrefix,
|
|
6007
|
+
config: opts.config
|
|
6008
|
+
}),
|
|
6009
|
+
...opts.sinceTimeoutMs !== void 0 && { sinceTimeoutMs: opts.sinceTimeoutMs },
|
|
6010
|
+
...opts.sincePollIntervalMs !== void 0 && { sincePollIntervalMs: opts.sincePollIntervalMs }
|
|
6011
|
+
}).fetch(request);
|
|
6012
|
+
outboundStatus = response.status;
|
|
6013
|
+
} catch (error) {
|
|
6014
|
+
caughtError = error;
|
|
6015
|
+
const { status, envelope } = mapError(error);
|
|
6016
|
+
outboundStatus = status;
|
|
6017
|
+
response = new Response(JSON.stringify(envelope), {
|
|
6018
|
+
status,
|
|
6019
|
+
headers: { "content-type": "application/json" }
|
|
6020
|
+
});
|
|
6021
|
+
} finally {
|
|
6022
|
+
flushCanonicalLine(obsCtx, obsCtx.recorder, {
|
|
6023
|
+
unit: "http",
|
|
6024
|
+
status: outboundStatus,
|
|
6025
|
+
outcome: deriveOutcome(request.method, outboundStatus, caughtError),
|
|
6026
|
+
...caughtError !== void 0 && { error: caughtError },
|
|
6027
|
+
extra: {
|
|
6028
|
+
method: request.method,
|
|
6029
|
+
path
|
|
6030
|
+
}
|
|
6031
|
+
});
|
|
6032
|
+
}
|
|
6033
|
+
return response;
|
|
6034
|
+
});
|
|
6035
|
+
};
|
|
6036
|
+
}
|
|
6037
|
+
/**
|
|
6038
|
+
* Auto-pick the default sink when the caller passed an
|
|
6039
|
+
* {@link ObservabilityConfig} without a `sink` field. On a TTY
|
|
6040
|
+
* (developer terminals) we prefer pretty output; otherwise JSON
|
|
6041
|
+
* (production hosts pipe stdout to a log aggregator).
|
|
6042
|
+
*
|
|
6043
|
+
* Returns a new config with `sink` defaulted; if the caller already
|
|
6044
|
+
* supplied a `sink` (function or shorthand string) we pass the
|
|
6045
|
+
* config through verbatim. Either way the caller's `level` (when
|
|
6046
|
+
* set) reaches LogTape unchanged.
|
|
6047
|
+
*
|
|
6048
|
+
* Exported for the test suite — the TTY check is otherwise a pure
|
|
6049
|
+
* read of `process.stdout.isTTY` and a default lookup, neither
|
|
6050
|
+
* worth a black-box round-trip.
|
|
6051
|
+
*/
|
|
6052
|
+
const resolveDefaultSink = (config) => {
|
|
6053
|
+
if (config.sink !== void 0) return config;
|
|
6054
|
+
const isTty = Boolean(process.stdout.isTTY);
|
|
6055
|
+
return {
|
|
6056
|
+
...config,
|
|
6057
|
+
sink: isTty ? prettyConsoleSink() : "console-json"
|
|
6058
|
+
};
|
|
6059
|
+
};
|
|
6060
|
+
//#endregion
|
|
5996
6061
|
//#region packages/adapter-node/src/app.ts
|
|
5997
6062
|
/**
|
|
5998
6063
|
* Build a Hono app that serves the baerly cascade plus Node-host
|
|
@@ -6031,8 +6096,6 @@ function createApp(opts) {
|
|
|
6031
6096
|
}
|
|
6032
6097
|
//#endregion
|
|
6033
6098
|
//#region packages/adapter-node/src/baerly-node.ts
|
|
6034
|
-
const DEFAULT_MAINTENANCE_INTERVAL_MS = 3600 * 1e3;
|
|
6035
|
-
const buildCurrentJsonKey = (app, tenant, collection) => `app/${app}/tenant/${tenant}/manifests/${collection}/current.json`;
|
|
6036
6099
|
/**
|
|
6037
6100
|
* Mount baerly on `node:http` with one call. Mirrors `baerlyWorker`
|
|
6038
6101
|
* from `@baerly/adapter-cloudflare`.
|
|
@@ -6041,19 +6104,20 @@ const buildCurrentJsonKey = (app, tenant, collection) => `app/${app}/tenant/${te
|
|
|
6041
6104
|
* - {@link createApp} → exposed as `handle.fetch` for in-process
|
|
6042
6105
|
* embedding; wrapped in `@hono/node-server.serve({ fetch, createServer })`
|
|
6043
6106
|
* lazily when `listen()` is called.
|
|
6044
|
-
* - Optional maintenance loop: each `intervalMs` tick fires one
|
|
6045
|
-
* {@link runMaintenanceTick} per `(tenant, collection)` pair
|
|
6046
|
-
* (cross-product of `opts.maintenance.tenants` × `.collections`).
|
|
6047
|
-
* The `currentJsonKey` is composed as
|
|
6048
|
-
* `app/<app>/tenant/<tenant>/manifests/<collection>/current.json` —
|
|
6049
|
-
* the canonical layout from the sync protocol.
|
|
6050
6107
|
* - SIGTERM + SIGINT handlers installed on `listen()` that call
|
|
6051
6108
|
* `close()` and `process.exit(0)`. On any error during close,
|
|
6052
6109
|
* `process.exit(1)`.
|
|
6053
6110
|
*
|
|
6054
|
-
*
|
|
6055
|
-
*
|
|
6056
|
-
* a
|
|
6111
|
+
* **Maintenance is in-band, not scheduled.** There is no `setInterval`,
|
|
6112
|
+
* no cron, and no `maintenance:` option: the kernel maintains itself on
|
|
6113
|
+
* a bare bucket with zero operator infrastructure. Compaction + GC run
|
|
6114
|
+
* INLINE on the (rare) write that crosses a maintenance trigger —
|
|
6115
|
+
* `createFetchHandler` threads a Node-tier `MaintenanceDispatch`
|
|
6116
|
+
* onto the per-request observability context, which the writer reads at
|
|
6117
|
+
* its post-CAS dispatch point. Reads never tick. Tune via the
|
|
6118
|
+
* `BAERLY_MAINTENANCE_MAX_FOLD_BYTES` / `BAERLY_MAINTENANCE_DISABLE`
|
|
6119
|
+
* env vars; for an explicit out-of-band sweep, call
|
|
6120
|
+
* `runScheduledMaintenance` from `@gusto/baerly-storage` directly.
|
|
6057
6121
|
*
|
|
6058
6122
|
* @example
|
|
6059
6123
|
* ```ts
|
|
@@ -6072,7 +6136,6 @@ const buildCurrentJsonKey = (app, tenant, collection) => `app/${app}/tenant/${te
|
|
|
6072
6136
|
* }),
|
|
6073
6137
|
* // No verifier needed when config.auth is "none" or "shared-secret".
|
|
6074
6138
|
* webRoot: "./dist/client",
|
|
6075
|
-
* maintenance: { collections: ["tickets", "comments"], tenants: ["acme"] },
|
|
6076
6139
|
* });
|
|
6077
6140
|
* await handle.listen(Number(process.env["PORT"] ?? 8080));
|
|
6078
6141
|
* ```
|
|
@@ -6096,30 +6159,11 @@ function baerlyNode(opts) {
|
|
|
6096
6159
|
...opts.sincePollIntervalMs !== void 0 && { sincePollIntervalMs: opts.sincePollIntervalMs }
|
|
6097
6160
|
});
|
|
6098
6161
|
let server;
|
|
6099
|
-
let maintenanceTimer;
|
|
6100
6162
|
let signalHandler;
|
|
6101
6163
|
let closed = false;
|
|
6102
|
-
const tick = async () => {
|
|
6103
|
-
const m = opts.maintenance;
|
|
6104
|
-
if (m === void 0) return;
|
|
6105
|
-
await Promise.all(m.tenants.flatMap((tenant) => m.collections.map(async (collection) => {
|
|
6106
|
-
try {
|
|
6107
|
-
await runMaintenanceTick({
|
|
6108
|
-
storage: opts.storage,
|
|
6109
|
-
currentJsonKey: buildCurrentJsonKey(opts.config.app, tenant, collection)
|
|
6110
|
-
});
|
|
6111
|
-
} catch (error) {
|
|
6112
|
-
console.error(`baerlyNode maintenance tick failed for tenant=${tenant} collection=${collection}`, error);
|
|
6113
|
-
}
|
|
6114
|
-
})));
|
|
6115
|
-
};
|
|
6116
6164
|
const close = async () => {
|
|
6117
6165
|
if (closed) return;
|
|
6118
6166
|
closed = true;
|
|
6119
|
-
if (maintenanceTimer !== void 0) {
|
|
6120
|
-
clearInterval(maintenanceTimer);
|
|
6121
|
-
maintenanceTimer = void 0;
|
|
6122
|
-
}
|
|
6123
6167
|
if (signalHandler !== void 0) {
|
|
6124
6168
|
process.off("SIGTERM", signalHandler);
|
|
6125
6169
|
process.off("SIGINT", signalHandler);
|
|
@@ -6170,13 +6214,6 @@ function baerlyNode(opts) {
|
|
|
6170
6214
|
httpServer.listen(port);
|
|
6171
6215
|
});
|
|
6172
6216
|
if (closed) return;
|
|
6173
|
-
if (opts.maintenance !== void 0) {
|
|
6174
|
-
const intervalMs = opts.maintenance.intervalMs ?? DEFAULT_MAINTENANCE_INTERVAL_MS;
|
|
6175
|
-
maintenanceTimer = setInterval(() => {
|
|
6176
|
-
tick();
|
|
6177
|
-
}, intervalMs);
|
|
6178
|
-
maintenanceTimer.unref();
|
|
6179
|
-
}
|
|
6180
6217
|
signalHandler = (sig) => {
|
|
6181
6218
|
console.log(`Received ${sig}; closing baerlyNode server`);
|
|
6182
6219
|
close().then(() => process.exit(0)).catch((error) => {
|
|
@@ -6194,6 +6231,6 @@ function baerlyNode(opts) {
|
|
|
6194
6231
|
};
|
|
6195
6232
|
}
|
|
6196
6233
|
//#endregion
|
|
6197
|
-
export { minioStorage as a,
|
|
6234
|
+
export { minioStorage as a, S3HttpStorage as c, gcsStorage as i, getRequestListener as n, r2Storage as o, fromEksPodIdentity as r, s3Storage as s, baerlyNode as t };
|
|
6198
6235
|
|
|
6199
|
-
//# sourceMappingURL=src-
|
|
6236
|
+
//# sourceMappingURL=src-DU1sCMlr.js.map
|