@gusto/baerly-storage 0.2.0 → 0.4.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.
Files changed (155) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +29 -0
  3. package/README.md +176 -70
  4. package/dist/API.md +213 -139
  5. package/dist/CHANGELOG.md +434 -0
  6. package/dist/RECIPES.md +125 -0
  7. package/dist/THIRD-PARTY-LICENSES.txt +238 -0
  8. package/dist/{app-config-C0Bbw_Z6.d.ts → app-config-DyiFK3_k.d.ts} +55 -11
  9. package/dist/app-config.d.ts +1 -1
  10. package/dist/auth.d.ts +1 -1
  11. package/dist/auth.js +301 -301
  12. package/dist/auth.js.map +1 -1
  13. package/dist/aws4fetch.esm-p7eEzLCs.js +1702 -0
  14. package/dist/aws4fetch.esm-p7eEzLCs.js.map +1 -0
  15. package/dist/baerly.js +35 -15
  16. package/dist/baerly.js.map +1 -1
  17. package/dist/baerly.spec.json +342 -0
  18. package/dist/bytes-BXdamO3L.js.map +1 -1
  19. package/dist/{client-DYZfoZb9.d.ts → client-Fe8CwB73.d.ts} +10 -10
  20. package/dist/client-react.d.ts +3 -3
  21. package/dist/client-react.js +4 -4
  22. package/dist/client-react.js.map +1 -1
  23. package/dist/client.d.ts +4 -4
  24. package/dist/client.js +3 -3
  25. package/dist/client.js.map +1 -1
  26. package/dist/{cloudflare-CINJPKCW.js → cloudflare-DzKBrUlg.js} +178 -2
  27. package/dist/cloudflare-DzKBrUlg.js.map +1 -0
  28. package/dist/cloudflare.d.ts +49 -6
  29. package/dist/cloudflare.js +59 -26
  30. package/dist/cloudflare.js.map +1 -1
  31. package/dist/config-1tv0-Yzm.js +2693 -0
  32. package/dist/config-1tv0-Yzm.js.map +1 -0
  33. package/dist/constants-CfeMWQWk.js +222 -0
  34. package/dist/constants-CfeMWQWk.js.map +1 -0
  35. package/dist/context-DRZ3tZ5l.js.map +1 -1
  36. package/dist/{cost-CQt1YRkA.js → cost-DSMIVqzL.js} +43 -42
  37. package/dist/cost-DSMIVqzL.js.map +1 -0
  38. package/dist/current-json-C6nhPOm1.js +190 -0
  39. package/dist/current-json-C6nhPOm1.js.map +1 -0
  40. package/dist/{db-BM3y2JQw.d.ts → db-DsPkOVEH.d.ts} +26 -108
  41. package/dist/{deploy-CrAbfgCq.js → deploy-DonTr-CV.js} +12 -5
  42. package/dist/deploy-DonTr-CV.js.map +1 -0
  43. package/dist/dev-vite.d.ts +11 -7
  44. package/dist/dev-vite.js +7 -6
  45. package/dist/dev-vite.js.map +1 -1
  46. package/dist/dev.d.ts +1 -1
  47. package/dist/dev.js +1 -1
  48. package/dist/{doctor-Db-hzPmE.js → doctor-DSIyCDg_.js} +14 -136
  49. package/dist/doctor-DSIyCDg_.js.map +1 -0
  50. package/dist/{dump-BYA55NLP.js → dump-Bh5k26VQ.js} +10 -31
  51. package/dist/dump-Bh5k26VQ.js.map +1 -0
  52. package/dist/{errors-DOdL95kK.js → errors-Dfa3p78c.js} +25 -5
  53. package/dist/errors-Dfa3p78c.js.map +1 -0
  54. package/dist/{export-Bhbz90-z.js → export-DtF5tDIM.js} +11 -32
  55. package/dist/{export-Bhbz90-z.js.map → export-DtF5tDIM.js.map} +1 -1
  56. package/dist/{fsck-CPPZWt9p.js → fsck-D_djMO5D.js} +28 -39
  57. package/dist/fsck-D_djMO5D.js.map +1 -0
  58. package/dist/{http-Cw8p6y5b.js → http-DxM9MflO.js} +151 -79
  59. package/dist/http-DxM9MflO.js.map +1 -0
  60. package/dist/http.d.ts +42 -26
  61. package/dist/http.js +3 -2
  62. package/dist/{index-DwDTWPSU.d.ts → index-0rZcMBwy.d.ts} +10 -7
  63. package/dist/{index-C3JAH1Yo.d.ts → index-B6oexfOB.d.ts} +9 -9
  64. package/dist/{index-cUY-36AN.d.ts → index-BNRh23K9.d.ts} +21 -5
  65. package/dist/{index-DSvwEUeF.d.ts → index-BYk9oCNf.d.ts} +240 -202
  66. package/dist/index.d.ts +6 -6
  67. package/dist/index.js +5 -5
  68. package/dist/{indexes-DAu2AkTW.d.ts → indexes-Dn9hbGQG.d.ts} +2 -2
  69. package/dist/{inspect-Bdbzvi-_.js → inspect-6WZ-pC7-.js} +21 -36
  70. package/dist/inspect-6WZ-pC7-.js.map +1 -0
  71. package/dist/key-Di6yyxFu.js +35 -0
  72. package/dist/key-Di6yyxFu.js.map +1 -0
  73. package/dist/{snapshot-SS8USDUF.js → log-tail-D98U1JBo.js} +179 -84
  74. package/dist/log-tail-D98U1JBo.js.map +1 -0
  75. package/dist/{maintenance-ClzBC1Vv.js → maintenance-B4Dki6Ig.js} +438 -176
  76. package/dist/maintenance-B4Dki6Ig.js.map +1 -0
  77. package/dist/{maintenance-BRrThz8V.d.ts → maintenance-B_e0T99L.d.ts} +114 -26
  78. package/dist/{maintenance-BvOv6BMM.js → maintenance-C7coQp4c.js} +217 -94
  79. package/dist/maintenance-C7coQp4c.js.map +1 -0
  80. package/dist/maintenance.d.ts +3 -2
  81. package/dist/maintenance.js +3 -2
  82. package/dist/node.d.ts +176 -68
  83. package/dist/node.js +3 -2
  84. package/dist/{normalize-XWY25_sG.js → normalize-rjnZLwS4.js} +2 -2
  85. package/dist/normalize-rjnZLwS4.js.map +1 -0
  86. package/dist/{observability-CpOiEN0k.js → observability-wzs3-BL_.js} +279 -109
  87. package/dist/observability-wzs3-BL_.js.map +1 -0
  88. package/dist/observability.d.ts +3 -3
  89. package/dist/observability.js +1 -1
  90. package/dist/{plan-DOTl21vq.js → plan-a7PJHBCy.js} +7 -4
  91. package/dist/plan-a7PJHBCy.js.map +1 -0
  92. package/dist/{query-BmiQy328.js → query-rAtXNQQB.js} +1063 -1202
  93. package/dist/query-rAtXNQQB.js.map +1 -0
  94. package/dist/{rebuild-index-DC_nR6wP.js → rebuild-index-BVzQSZlm.js} +10 -32
  95. package/dist/rebuild-index-BVzQSZlm.js.map +1 -0
  96. package/dist/{request-BEF_OvMh.js → request-u0M51mhJ.js} +3 -3
  97. package/dist/{request-BEF_OvMh.js.map → request-u0M51mhJ.js.map} +1 -1
  98. package/dist/restore-R-4rbciV.js +778 -0
  99. package/dist/restore-R-4rbciV.js.map +1 -0
  100. package/dist/runtime-spec-qL3_lTTU.js +391 -0
  101. package/dist/runtime-spec-qL3_lTTU.js.map +1 -0
  102. package/dist/s3-http-B-z8th6O.d.ts +60 -0
  103. package/dist/s3.d.ts +47 -0
  104. package/dist/s3.js +45 -0
  105. package/dist/s3.js.map +1 -0
  106. package/dist/{shared-secret-BJdSwpgw.js → shared-secret-DgEicd3x.js} +13 -5
  107. package/dist/shared-secret-DgEicd3x.js.map +1 -0
  108. package/dist/src-BG20LZs7.js +2271 -0
  109. package/dist/src-BG20LZs7.js.map +1 -0
  110. package/dist/{src-zhEAmmF7.js → src-CYHFDrKz.js} +82 -99
  111. package/dist/src-CYHFDrKz.js.map +1 -0
  112. package/dist/{src-QQ7jDeL2.js → src-DYZ4H1aF.js} +44 -23
  113. package/dist/src-DYZ4H1aF.js.map +1 -0
  114. package/dist/subcommand-DoDA-K7d.js +197 -0
  115. package/dist/subcommand-DoDA-K7d.js.map +1 -0
  116. package/dist/time-DUqvFMHq.js +119 -0
  117. package/dist/time-DUqvFMHq.js.map +1 -0
  118. package/dist/{usage-CLjirdD-.js → usage-DBV1eQHC.js} +7 -22
  119. package/dist/usage-DBV1eQHC.js.map +1 -0
  120. package/dist/{validate-DCq_0DIn.js → validate-DtljsCh1.js} +51 -51
  121. package/dist/{validate-DCq_0DIn.js.map → validate-DtljsCh1.js.map} +1 -1
  122. package/dist/wire-izfGZDvr.js.map +1 -1
  123. package/package.json +77 -42
  124. package/dist/cloudflare-CINJPKCW.js.map +0 -1
  125. package/dist/config-DVfDGyw1.js +0 -278
  126. package/dist/config-DVfDGyw1.js.map +0 -1
  127. package/dist/cost-CQt1YRkA.js.map +0 -1
  128. package/dist/current-json-C-EyJqs0.js +0 -354
  129. package/dist/current-json-C-EyJqs0.js.map +0 -1
  130. package/dist/deploy-CrAbfgCq.js.map +0 -1
  131. package/dist/doctor-Db-hzPmE.js.map +0 -1
  132. package/dist/dump-BYA55NLP.js.map +0 -1
  133. package/dist/errors-DOdL95kK.js.map +0 -1
  134. package/dist/fsck-CPPZWt9p.js.map +0 -1
  135. package/dist/http-Cw8p6y5b.js.map +0 -1
  136. package/dist/inspect-Bdbzvi-_.js.map +0 -1
  137. package/dist/maintenance-BvOv6BMM.js.map +0 -1
  138. package/dist/maintenance-ClzBC1Vv.js.map +0 -1
  139. package/dist/normalize-XWY25_sG.js.map +0 -1
  140. package/dist/observability-CpOiEN0k.js.map +0 -1
  141. package/dist/plan-DOTl21vq.js.map +0 -1
  142. package/dist/query-BmiQy328.js.map +0 -1
  143. package/dist/rebuild-index-DC_nR6wP.js.map +0 -1
  144. package/dist/restore-C6IcmLeA.js +0 -771
  145. package/dist/restore-C6IcmLeA.js.map +0 -1
  146. package/dist/shared-secret-BJdSwpgw.js.map +0 -1
  147. package/dist/snapshot-SS8USDUF.js.map +0 -1
  148. package/dist/src-DU1sCMlr.js +0 -6236
  149. package/dist/src-DU1sCMlr.js.map +0 -1
  150. package/dist/src-QQ7jDeL2.js.map +0 -1
  151. package/dist/src-zhEAmmF7.js.map +0 -1
  152. package/dist/subcommand-DZcHcsYp.js +0 -5122
  153. package/dist/subcommand-DZcHcsYp.js.map +0 -1
  154. package/dist/usage-CLjirdD-.js.map +0 -1
  155. /package/dist/{chunk-EAsCxrDo.js → rolldown-runtime-EAsCxrDo.js} +0 -0
@@ -1,10 +1,36 @@
1
- import { r as logSeqStartOf } from "./current-json-C-EyJqs0.js";
2
- import { t as BaerlyError } from "./errors-DOdL95kK.js";
3
- import { x as validateWire } from "./maintenance-ClzBC1Vv.js";
4
- import { c as lsnParts, n as runAllWithMeta, r as runByIdWithMeta } from "./query-BmiQy328.js";
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 serializeError, l as getLogger, s as CATEGORY, u as errorEnvelope } from "./observability-CpOiEN0k.js";
7
- //#region node_modules/.pnpm/hono@4.12.23/node_modules/hono/dist/compose.js
7
+ import { i as str2uintDesc } from "./time-DUqvFMHq.js";
8
+ import { n as getCurrentContext } from "./context-DRZ3tZ5l.js";
9
+ //#region packages/protocol/src/log.ts
10
+ /**
11
+ * Extract the `session` and `seq` embedded in an `lsn` of shape
12
+ * `<base32-time>_<session>_<seq>`. The seq portion is decoded as a
13
+ * descending base-32 integer (matches `countKey` in `./types`).
14
+ *
15
+ * Use this at the `/v1/since` cursor-decoding boundary, where a
16
+ * client resumes from an opaque `SinceResponse.next_cursor` and no
17
+ * `LogEntry` is in scope. When iterating `LogEntry` records, read
18
+ * `entry.session` / `entry.seq` directly instead.
19
+ *
20
+ * Throws on malformed input; callers should pass only lsns minted
21
+ * by `Writer.commit` (see
22
+ * `packages/server/src/writer.ts`).
23
+ */
24
+ const lsnParts = (lsn) => {
25
+ const parts = lsn.split("_");
26
+ if (parts.length !== 3) throw new BaerlyError("InvalidResponse", `invalid lsn shape: ${lsn}`);
27
+ return {
28
+ session: parts[1],
29
+ seq: str2uintDesc(parts[2], 53)
30
+ };
31
+ };
32
+ //#endregion
33
+ //#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/compose.js
8
34
  var compose = (middleware, onError, onNotFound) => {
9
35
  return (context, next) => {
10
36
  let index = -1;
@@ -35,10 +61,10 @@ var compose = (middleware, onError, onNotFound) => {
35
61
  };
36
62
  };
37
63
  //#endregion
38
- //#region node_modules/.pnpm/hono@4.12.23/node_modules/hono/dist/request/constants.js
64
+ //#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/request/constants.js
39
65
  var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
40
66
  //#endregion
41
- //#region node_modules/.pnpm/hono@4.12.23/node_modules/hono/dist/utils/body.js
67
+ //#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/utils/body.js
42
68
  var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
43
69
  const { all = false, dot = false } = options;
44
70
  const contentType = (request instanceof HonoRequest ? request.raw.headers : request.headers).get("Content-Type");
@@ -86,7 +112,7 @@ var handleParsingNestedValues = (form, key, value) => {
86
112
  });
87
113
  };
88
114
  //#endregion
89
- //#region node_modules/.pnpm/hono@4.12.23/node_modules/hono/dist/utils/url.js
115
+ //#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/utils/url.js
90
116
  var tryDecode = (str, decoder) => {
91
117
  try {
92
118
  return decoder(str);
@@ -178,7 +204,7 @@ var getQueryParams = (url, key) => {
178
204
  };
179
205
  var decodeURIComponent_ = decodeURIComponent;
180
206
  //#endregion
181
- //#region node_modules/.pnpm/hono@4.12.23/node_modules/hono/dist/request.js
207
+ //#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/request.js
182
208
  var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
183
209
  var HonoRequest = class {
184
210
  /**
@@ -450,7 +476,7 @@ var HonoRequest = class {
450
476
  }
451
477
  };
452
478
  //#endregion
453
- //#region node_modules/.pnpm/hono@4.12.23/node_modules/hono/dist/utils/html.js
479
+ //#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/utils/html.js
454
480
  var HtmlEscapedCallbackPhase = {
455
481
  Stringify: 1,
456
482
  BeforeStream: 2,
@@ -480,7 +506,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
480
506
  else return resStr;
481
507
  };
482
508
  //#endregion
483
- //#region node_modules/.pnpm/hono@4.12.23/node_modules/hono/dist/context.js
509
+ //#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/context.js
484
510
  var TEXT_PLAIN = "text/plain; charset=UTF-8";
485
511
  var setDefaultContentType = (contentType, headers) => {
486
512
  return {
@@ -841,7 +867,7 @@ var Context = class {
841
867
  };
842
868
  };
843
869
  //#endregion
844
- //#region node_modules/.pnpm/hono@4.12.23/node_modules/hono/dist/router.js
870
+ //#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/router.js
845
871
  var METHODS = [
846
872
  "get",
847
873
  "post",
@@ -852,10 +878,10 @@ var METHODS = [
852
878
  ];
853
879
  var UnsupportedPathError = class extends Error {};
854
880
  //#endregion
855
- //#region node_modules/.pnpm/hono@4.12.23/node_modules/hono/dist/utils/constants.js
881
+ //#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/utils/constants.js
856
882
  var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
857
883
  //#endregion
858
- //#region node_modules/.pnpm/hono@4.12.23/node_modules/hono/dist/hono-base.js
884
+ //#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/hono-base.js
859
885
  var notFoundHandler = (c) => {
860
886
  return c.text("404 Not Found", 404);
861
887
  };
@@ -1189,7 +1215,7 @@ var Hono$1 = class _Hono {
1189
1215
  };
1190
1216
  };
1191
1217
  //#endregion
1192
- //#region node_modules/.pnpm/hono@4.12.23/node_modules/hono/dist/router/pattern-router/router.js
1218
+ //#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/router/pattern-router/router.js
1193
1219
  var emptyParams = /* @__PURE__ */ Object.create(null);
1194
1220
  var PatternRouter = class {
1195
1221
  name = "PatternRouter";
@@ -1228,53 +1254,14 @@ var PatternRouter = class {
1228
1254
  }
1229
1255
  };
1230
1256
  //#endregion
1231
- //#region node_modules/.pnpm/hono@4.12.23/node_modules/hono/dist/preset/tiny.js
1257
+ //#region node_modules/.pnpm/hono@4.12.27/node_modules/hono/dist/preset/tiny.js
1232
1258
  var Hono = class extends Hono$1 {
1233
1259
  constructor(options = {}) {
1234
1260
  super(options);
1235
1261
  this.router = new PatternRouter();
1236
1262
  }
1237
1263
  };
1238
- //#endregion
1239
- //#region packages/server/src/http/since.ts
1240
- /**
1241
- * Long-poll `GET /v1/since` handler core. Two exports:
1242
- *
1243
- * - {@link longPollSince} — the long-poll itself. Fast path first;
1244
- * if `listEventsSince` already sees events, return immediately.
1245
- * Otherwise race a poll loop against a 25 s wall-clock timeout and
1246
- * return either the next batch of events or
1247
- * `{ events: [], next_cursor: <same> }` ("nothing changed within
1248
- * the budget").
1249
- * - {@link listEventsSince} — one poll cycle. Reads `current.json`,
1250
- * validates the caller's cursor against `log_seq_start`, lists the
1251
- * log keys strictly-greater than the cursor's key, GETs each body,
1252
- * and returns the parsed `LogEntry`s in causal order.
1253
- *
1254
- * The handler is wired into the Hono router (`router.ts`); the
1255
- * router itself owns request parsing and error → HTTP mapping. This
1256
- * module owns the I/O + cursor semantics.
1257
- *
1258
- * Cost model. While a long-poll connection is active the per-poll
1259
- * cost is one `Storage.get` of `current.json` plus one `Storage.get`
1260
- * per log entry yielded. An idle reader (no new entries) pays one
1261
- * Class A op per inner poll; with the production defaults
1262
- * (25 s / 1 s) that is 25 ops per active connection. The
1263
- * `< 1 Class A op / writer / hour` cost-model bound (see
1264
- * `docs/spec/sync-protocol.md`) is for an *idle* reader — i.e. a
1265
- * client that is *not* currently holding a long-poll open.
1266
- * Subscribers paying for real-time-ish delivery are by definition
1267
- * non-idle.
1268
- */
1269
- /**
1270
- * Validation regex for an opaque LSN cursor. Matches the shape minted
1271
- * by `Writer.commit` (see
1272
- * `packages/server/src/writer.ts`) and described on
1273
- * {@link LogEntry.lsn} — `<base32-time>_<session>_<seq>` where
1274
- * base-32 is `[0-9a-v]` and the trailing seq is two characters.
1275
- * Mirrored from `tests/integration/log-emit.test.ts:77`.
1276
- */
1277
- const LSN_RE = /^[0-9a-v]+_[0-9a-v]+_[0-9a-v]{2}$/;
1264
+ const LSN_RE = new RegExp(`^[0-9a-v]+_[0-9a-v]+_[0-9a-v]{${Math.ceil(53 / 5)}}$`);
1278
1265
  /**
1279
1266
  * Hard cap on log entries returned in a single poll cycle. 1024 is
1280
1267
  * comfortably above the largest expected per-poll batch under the
@@ -1295,8 +1282,7 @@ const DEFAULT_MAX_EVENTS = 1024;
1295
1282
  */
1296
1283
  const DEFAULT_TIMEOUT_MS = 25e3;
1297
1284
  /**
1298
- * Default 1 s inner-poll interval. 25 polls × 1 list = 25 Class A
1299
- * ops per active long-poll connection. See module docstring for the
1285
+ * Default 1 s inner-poll interval. See module docstring for the
1300
1286
  * cost-model trade-off.
1301
1287
  *
1302
1288
  * Per-request override is via the `pollIntervalMs` field on
@@ -1426,7 +1412,7 @@ async function listEventsSince(opts) {
1426
1412
  const read = await db.getCurrentJson(collection, signalOpt(signal));
1427
1413
  if (read === null) return [];
1428
1414
  const logSeqStart = logSeqStartOf(read.json);
1429
- const nextSeq = read.json.next_seq;
1415
+ const tail = await db.probeLogTail(collection, Math.max(logSeqStart, read.json.tail_hint), signalOpt(signal));
1430
1416
  let startSeq;
1431
1417
  if (cursor.length === 0) startSeq = logSeqStart;
1432
1418
  else {
@@ -1434,7 +1420,7 @@ async function listEventsSince(opts) {
1434
1420
  if (cursorSeq < logSeqStart) throw new BaerlyError("SchemaError", `cursor ${JSON.stringify(cursor)} points to a log entry that has been folded into a snapshot (log_seq_start=${logSeqStart}); re-bootstrap from a snapshot read before resuming`);
1435
1421
  startSeq = cursorSeq + 1;
1436
1422
  }
1437
- const endSeq = Math.min(nextSeq, startSeq + DEFAULT_MAX_EVENTS);
1423
+ const endSeq = Math.min(tail, startSeq + DEFAULT_MAX_EVENTS);
1438
1424
  const entries = [];
1439
1425
  for (let s = startSeq; s < endSeq; s++) {
1440
1426
  const entry = await db.getLogEntry(collection, s, signalOpt(signal));
@@ -1552,7 +1538,7 @@ function createRouter(options) {
1552
1538
  });
1553
1539
  app.get("/v1/count", async (c) => {
1554
1540
  const collection = c.req.query("collection");
1555
- 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.");
1556
1542
  const wire = parseWhereParam(c);
1557
1543
  const { rows, manifestPointer, fresh } = await runAllWithMeta(db.collectionReadContext(collection), {
1558
1544
  wire,
@@ -1615,7 +1601,7 @@ const MAX_BODY_BYTES = 1 << 20;
1615
1601
  */
1616
1602
  const assertJsonBodyField = (body, field) => {
1617
1603
  const value = typeof body === "object" && body !== null ? body[field] : void 0;
1618
- 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);
1619
1605
  return value;
1620
1606
  };
1621
1607
  /**
@@ -1643,9 +1629,13 @@ const parseWhereParam = (c) => {
1643
1629
  try {
1644
1630
  parsed = JSON.parse(whereParam);
1645
1631
  } catch {
1646
- 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);
1647
1638
  }
1648
- return validateWire(parsed);
1649
1639
  };
1650
1640
  /**
1651
1641
  * Parse `?limit=<n>` as a non-negative safe integer. Returns
@@ -1674,36 +1664,118 @@ function parseOrder(raw) {
1674
1664
  try {
1675
1665
  parsed = JSON.parse(raw);
1676
1666
  } catch {
1677
- 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);
1678
1668
  }
1679
- 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);
1680
1670
  return parsed;
1681
1671
  }
1682
- const ERROR_TO_STATUS = new Map([
1672
+ const ERROR_TO_STATUS = /* @__PURE__ */ new Map([
1683
1673
  ["Unauthorized", 401],
1684
1674
  ["AccessDenied", 403],
1685
1675
  ["NotFound", 404],
1686
1676
  ["Conflict", 409],
1687
1677
  ["PayloadTooLarge", 413],
1688
1678
  ["SchemaError", 400],
1689
- ["InvalidConfig", 400]
1679
+ ["InvalidConfig", 400],
1680
+ ["UnsatisfiablePredicate", 400],
1681
+ ["NetworkError", 502],
1682
+ ["InvalidResponse", 502]
1690
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
+ };
1691
1752
  /**
1692
1753
  * Map an unknown thrown value onto the wire envelope plus an HTTP
1693
1754
  * status code. The mapping is keyed by `BaerlyError.code` so any future
1694
- * code addition forces a re-check here (currently unmapped codes fall
1695
- * through to 500 by design — see the `NetworkError` / `InvalidResponse`
1696
- * / `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`.
1697
1757
  *
1698
1758
  * Public via `@gusto/baerly-storage/http` for the embed-by-hand recipe
1699
1759
  * (your own Hono / Express / Fastify app calling `Db` directly).
1700
1760
  * The `HttpErrorEnvelope` shape is locked; do not mutate it.
1701
1761
  */
1702
1762
  function mapError(err) {
1703
- if (err instanceof BaerlyError) return {
1704
- status: ERROR_TO_STATUS.get(err.code) ?? 500,
1705
- envelope: errorEnvelope(err.code, err.message, err.issues)
1706
- };
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
+ }
1707
1779
  getLogger(CATEGORY.http).error("unhandled_error", { error: serializeError(err) });
1708
1780
  return {
1709
1781
  status: 500,
@@ -1743,14 +1815,14 @@ async function readJsonBody(c, maxBytes) {
1743
1815
  if (error instanceof BaerlyError) throw error;
1744
1816
  throw new BaerlyError("SchemaError", `Failed to read request body: ${error instanceof Error ? error.message : String(error)}`);
1745
1817
  }
1746
- 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);
1747
1819
  try {
1748
1820
  return JSON.parse(raw);
1749
1821
  } catch {
1750
- 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);
1751
1823
  }
1752
1824
  }
1753
1825
  //#endregion
1754
1826
  export { longPollSince as a, listEventsSince as i, createRouter as n, Hono as o, mapError as r, MAX_BODY_BYTES as t };
1755
1827
 
1756
- //# sourceMappingURL=http-Cw8p6y5b.js.map
1828
+ //# sourceMappingURL=http-DxM9MflO.js.map