@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.
- package/LICENSE +202 -0
- package/NOTICE +29 -0
- package/README.md +176 -70
- package/dist/API.md +213 -139
- package/dist/CHANGELOG.md +434 -0
- package/dist/RECIPES.md +125 -0
- package/dist/THIRD-PARTY-LICENSES.txt +238 -0
- package/dist/{app-config-C0Bbw_Z6.d.ts → app-config-DyiFK3_k.d.ts} +55 -11
- package/dist/app-config.d.ts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +301 -301
- 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/bytes-BXdamO3L.js.map +1 -1
- package/dist/{client-DYZfoZb9.d.ts → client-Fe8CwB73.d.ts} +10 -10
- 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/client.js.map +1 -1
- package/dist/{cloudflare-CINJPKCW.js → cloudflare-DzKBrUlg.js} +178 -2
- package/dist/cloudflare-DzKBrUlg.js.map +1 -0
- package/dist/cloudflare.d.ts +49 -6
- package/dist/cloudflare.js +59 -26
- 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/context-DRZ3tZ5l.js.map +1 -1
- package/dist/{cost-CQt1YRkA.js → cost-DSMIVqzL.js} +43 -42
- package/dist/cost-DSMIVqzL.js.map +1 -0
- package/dist/current-json-C6nhPOm1.js +190 -0
- package/dist/current-json-C6nhPOm1.js.map +1 -0
- package/dist/{db-BM3y2JQw.d.ts → db-DsPkOVEH.d.ts} +26 -108
- package/dist/{deploy-CrAbfgCq.js → deploy-DonTr-CV.js} +12 -5
- package/dist/deploy-DonTr-CV.js.map +1 -0
- package/dist/dev-vite.d.ts +11 -7
- package/dist/dev-vite.js +7 -6
- package/dist/dev-vite.js.map +1 -1
- package/dist/dev.d.ts +1 -1
- package/dist/dev.js +1 -1
- package/dist/{doctor-Db-hzPmE.js → doctor-DSIyCDg_.js} +14 -136
- package/dist/doctor-DSIyCDg_.js.map +1 -0
- package/dist/{dump-BYA55NLP.js → dump-Bh5k26VQ.js} +10 -31
- 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-Bhbz90-z.js → export-DtF5tDIM.js} +11 -32
- package/dist/{export-Bhbz90-z.js.map → export-DtF5tDIM.js.map} +1 -1
- package/dist/{fsck-CPPZWt9p.js → fsck-D_djMO5D.js} +28 -39
- package/dist/fsck-D_djMO5D.js.map +1 -0
- package/dist/{http-Cw8p6y5b.js → http-DxM9MflO.js} +151 -79
- package/dist/http-DxM9MflO.js.map +1 -0
- package/dist/http.d.ts +42 -26
- package/dist/http.js +3 -2
- package/dist/{index-DwDTWPSU.d.ts → index-0rZcMBwy.d.ts} +10 -7
- package/dist/{index-C3JAH1Yo.d.ts → index-B6oexfOB.d.ts} +9 -9
- package/dist/{index-cUY-36AN.d.ts → index-BNRh23K9.d.ts} +21 -5
- package/dist/{index-DSvwEUeF.d.ts → index-BYk9oCNf.d.ts} +240 -202
- package/dist/index.d.ts +6 -6
- package/dist/index.js +5 -5
- package/dist/{indexes-DAu2AkTW.d.ts → indexes-Dn9hbGQG.d.ts} +2 -2
- package/dist/{inspect-Bdbzvi-_.js → inspect-6WZ-pC7-.js} +21 -36
- 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/{snapshot-SS8USDUF.js → log-tail-D98U1JBo.js} +179 -84
- package/dist/log-tail-D98U1JBo.js.map +1 -0
- package/dist/{maintenance-ClzBC1Vv.js → maintenance-B4Dki6Ig.js} +438 -176
- package/dist/maintenance-B4Dki6Ig.js.map +1 -0
- package/dist/{maintenance-BRrThz8V.d.ts → maintenance-B_e0T99L.d.ts} +114 -26
- package/dist/{maintenance-BvOv6BMM.js → maintenance-C7coQp4c.js} +217 -94
- package/dist/maintenance-C7coQp4c.js.map +1 -0
- package/dist/maintenance.d.ts +3 -2
- package/dist/maintenance.js +3 -2
- package/dist/node.d.ts +176 -68
- 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-CpOiEN0k.js → observability-wzs3-BL_.js} +279 -109
- package/dist/observability-wzs3-BL_.js.map +1 -0
- package/dist/observability.d.ts +3 -3
- package/dist/observability.js +1 -1
- package/dist/{plan-DOTl21vq.js → plan-a7PJHBCy.js} +7 -4
- package/dist/plan-a7PJHBCy.js.map +1 -0
- package/dist/{query-BmiQy328.js → query-rAtXNQQB.js} +1063 -1202
- package/dist/query-rAtXNQQB.js.map +1 -0
- package/dist/{rebuild-index-DC_nR6wP.js → rebuild-index-BVzQSZlm.js} +10 -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-R-4rbciV.js +778 -0
- package/dist/restore-R-4rbciV.js.map +1 -0
- package/dist/runtime-spec-qL3_lTTU.js +391 -0
- package/dist/runtime-spec-qL3_lTTU.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-BG20LZs7.js +2271 -0
- package/dist/src-BG20LZs7.js.map +1 -0
- package/dist/{src-zhEAmmF7.js → src-CYHFDrKz.js} +82 -99
- package/dist/src-CYHFDrKz.js.map +1 -0
- package/dist/{src-QQ7jDeL2.js → src-DYZ4H1aF.js} +44 -23
- package/dist/src-DYZ4H1aF.js.map +1 -0
- package/dist/subcommand-DoDA-K7d.js +197 -0
- 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-CLjirdD-.js → usage-DBV1eQHC.js} +7 -22
- package/dist/usage-DBV1eQHC.js.map +1 -0
- package/dist/{validate-DCq_0DIn.js → validate-DtljsCh1.js} +51 -51
- package/dist/{validate-DCq_0DIn.js.map → validate-DtljsCh1.js.map} +1 -1
- package/dist/wire-izfGZDvr.js.map +1 -1
- package/package.json +77 -42
- package/dist/cloudflare-CINJPKCW.js.map +0 -1
- package/dist/config-DVfDGyw1.js +0 -278
- package/dist/config-DVfDGyw1.js.map +0 -1
- package/dist/cost-CQt1YRkA.js.map +0 -1
- package/dist/current-json-C-EyJqs0.js +0 -354
- package/dist/current-json-C-EyJqs0.js.map +0 -1
- package/dist/deploy-CrAbfgCq.js.map +0 -1
- package/dist/doctor-Db-hzPmE.js.map +0 -1
- package/dist/dump-BYA55NLP.js.map +0 -1
- package/dist/errors-DOdL95kK.js.map +0 -1
- package/dist/fsck-CPPZWt9p.js.map +0 -1
- package/dist/http-Cw8p6y5b.js.map +0 -1
- package/dist/inspect-Bdbzvi-_.js.map +0 -1
- package/dist/maintenance-BvOv6BMM.js.map +0 -1
- package/dist/maintenance-ClzBC1Vv.js.map +0 -1
- package/dist/normalize-XWY25_sG.js.map +0 -1
- package/dist/observability-CpOiEN0k.js.map +0 -1
- package/dist/plan-DOTl21vq.js.map +0 -1
- package/dist/query-BmiQy328.js.map +0 -1
- package/dist/rebuild-index-DC_nR6wP.js.map +0 -1
- package/dist/restore-C6IcmLeA.js +0 -771
- package/dist/restore-C6IcmLeA.js.map +0 -1
- package/dist/shared-secret-BJdSwpgw.js.map +0 -1
- package/dist/snapshot-SS8USDUF.js.map +0 -1
- package/dist/src-DU1sCMlr.js +0 -6236
- package/dist/src-DU1sCMlr.js.map +0 -1
- package/dist/src-QQ7jDeL2.js.map +0 -1
- package/dist/src-zhEAmmF7.js.map +0 -1
- package/dist/subcommand-DZcHcsYp.js +0 -5122
- package/dist/subcommand-DZcHcsYp.js.map +0 -1
- package/dist/usage-CLjirdD-.js.map +0 -1
- /package/dist/{chunk-EAsCxrDo.js → rolldown-runtime-EAsCxrDo.js} +0 -0
|
@@ -1,10 +1,36 @@
|
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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
|
|
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(
|
|
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
|
|
1695
|
-
* through to 500 by design —
|
|
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)
|
|
1704
|
-
|
|
1705
|
-
|
|
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-
|
|
1828
|
+
//# sourceMappingURL=http-DxM9MflO.js.map
|