@gusto/baerly-storage 0.6.0 → 0.7.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 (218) hide show
  1. package/README.md +47 -124
  2. package/dist/API.md +161 -512
  3. package/dist/CHANGELOG.md +1137 -378
  4. package/dist/RECIPES.md +398 -80
  5. package/dist/THIRD-PARTY-LICENSES.txt +5 -26
  6. package/dist/{app-config-DyiFK3_k.d.ts → app-config-C6qW7m8S.d.ts} +119 -111
  7. package/dist/app-config.d.ts +31 -1
  8. package/dist/app-config.js +1 -2
  9. package/dist/app-config.js.map +1 -1
  10. package/dist/auth.d.ts +33 -28
  11. package/dist/auth.js +549 -985
  12. package/dist/auth.js.map +1 -1
  13. package/dist/baerly.js +130 -138
  14. package/dist/baerly.js.map +1 -1
  15. package/dist/baerly.spec.json +97 -22
  16. package/dist/capacity-warning-header-BlVopyiI.js +16 -0
  17. package/dist/capacity-warning-header-BlVopyiI.js.map +1 -0
  18. package/dist/{client-ypCm3zjt.d.ts → client-CHQTXpef.d.ts} +121 -36
  19. package/dist/client-react.d.ts +67 -20
  20. package/dist/client-react.js +240 -54
  21. package/dist/client-react.js.map +1 -1
  22. package/dist/client.d.ts +5 -4
  23. package/dist/client.js +51 -16
  24. package/dist/client.js.map +1 -1
  25. package/dist/{cloudflare-wrVYf4bb.js → cloudflare-CKHYXccw.js} +61 -82
  26. package/dist/cloudflare-CKHYXccw.js.map +1 -0
  27. package/dist/cloudflare.d.ts +106 -71
  28. package/dist/cloudflare.js +334 -271
  29. package/dist/cloudflare.js.map +1 -1
  30. package/dist/code-resolution-CL_7L0wS.js +22 -0
  31. package/dist/code-resolution-CL_7L0wS.js.map +1 -0
  32. package/dist/collection-api-DbyhLAY8.d.ts +1001 -0
  33. package/dist/config-DEzInG6M.js +4035 -0
  34. package/dist/config-DEzInG6M.js.map +1 -0
  35. package/dist/constants-D3GSH3tc.js +469 -0
  36. package/dist/constants-D3GSH3tc.js.map +1 -0
  37. package/dist/{context-DRZ3tZ5l.js → context-rlpSnHFA.js} +17 -17
  38. package/dist/context-rlpSnHFA.js.map +1 -0
  39. package/dist/cost-B52llVDx.js +330 -0
  40. package/dist/cost-B52llVDx.js.map +1 -0
  41. package/dist/{current-json-C6nhPOm1.js → current-json-CC6lE4Aj.js} +115 -32
  42. package/dist/current-json-CC6lE4Aj.js.map +1 -0
  43. package/dist/db-plFUNTSF.d.ts +130 -0
  44. package/dist/db-read-seams-BSs0m1z1.js +3261 -0
  45. package/dist/db-read-seams-BSs0m1z1.js.map +1 -0
  46. package/dist/{deploy-Di_Q01qx.js → deploy-Obj4nE-Z.js} +10 -14
  47. package/dist/deploy-Obj4nE-Z.js.map +1 -0
  48. package/dist/{dev-banner-CWHIk8tH.d.ts → dev-banner-B5AUHmu1.d.ts} +1 -4
  49. package/dist/dev-landing-BI5UdmOb.d.ts +32 -0
  50. package/dist/dev-landing-CD-si4dW.js +50 -0
  51. package/dist/dev-landing-CD-si4dW.js.map +1 -0
  52. package/dist/dev-vite.d.ts +9 -14
  53. package/dist/dev-vite.js +11 -10
  54. package/dist/dev-vite.js.map +1 -1
  55. package/dist/dev.d.ts +3 -2
  56. package/dist/dev.js +2 -1
  57. package/dist/doctor-BA0i-YAN.js +270 -0
  58. package/dist/doctor-BA0i-YAN.js.map +1 -0
  59. package/dist/dump-D1vX8ozg.js +133 -0
  60. package/dist/dump-D1vX8ozg.js.map +1 -0
  61. package/dist/errors-7Rk1HGCE.js +160 -0
  62. package/dist/errors-7Rk1HGCE.js.map +1 -0
  63. package/dist/{validate-DtljsCh1.js → export-BVL2EvYE.js} +409 -19
  64. package/dist/export-BVL2EvYE.js.map +1 -0
  65. package/dist/fsck-BWkPgov4.js +145 -0
  66. package/dist/fsck-BWkPgov4.js.map +1 -0
  67. package/dist/{gcs-admin-Bx6xSNJj.d.ts → gcs-admin-Dso1HWQj.d.ts} +18 -14
  68. package/dist/gcs.d.ts +19 -7
  69. package/dist/gcs.js +1 -2
  70. package/dist/{goog4-signer-Z7KnJ1su.js → goog4-signer-CeLIABoE.js} +102 -92
  71. package/dist/goog4-signer-CeLIABoE.js.map +1 -0
  72. package/dist/{http-7zT29K3P.js → http-Z5rZyYMX.js} +898 -271
  73. package/dist/http-Z5rZyYMX.js.map +1 -0
  74. package/dist/http-transport-DNUM8kU-.js +1299 -0
  75. package/dist/http-transport-DNUM8kU-.js.map +1 -0
  76. package/dist/http.d.ts +366 -294
  77. package/dist/http.js +2 -2
  78. package/dist/index-JJrIu1pO.d.ts +135 -0
  79. package/dist/index-LEgHN0qJ.d.ts +50 -0
  80. package/dist/{index-DP3ClvcA.d.ts → index-RiEYj8t0.d.ts} +291 -78
  81. package/dist/index.d.ts +27 -6
  82. package/dist/index.js +3 -5
  83. package/dist/inspect-BTsVYZKd.js +196 -0
  84. package/dist/inspect-BTsVYZKd.js.map +1 -0
  85. package/dist/{key-Di6yyxFu.js → key-C4FPZ9Io.js} +3 -4
  86. package/dist/{key-Di6yyxFu.js.map → key-C4FPZ9Io.js.map} +1 -1
  87. package/dist/ledger-Dj_bGgo0.js +192 -0
  88. package/dist/ledger-Dj_bGgo0.js.map +1 -0
  89. package/dist/legacy-names-DgZBtgOh.js +47 -0
  90. package/dist/legacy-names-DgZBtgOh.js.map +1 -0
  91. package/dist/log-C9W15Dfo.d.ts +94 -0
  92. package/dist/log-tail-DWJbneBF.js +142 -0
  93. package/dist/log-tail-DWJbneBF.js.map +1 -0
  94. package/dist/log-walk-C-vA-WGJ.js +111 -0
  95. package/dist/log-walk-C-vA-WGJ.js.map +1 -0
  96. package/dist/maintenance-Dd-Yakqj.js +1709 -0
  97. package/dist/maintenance-Dd-Yakqj.js.map +1 -0
  98. package/dist/maintenance-DevB6z4e.js +2237 -0
  99. package/dist/maintenance-DevB6z4e.js.map +1 -0
  100. package/dist/maintenance.d.ts +100 -3
  101. package/dist/maintenance.js +1 -3
  102. package/dist/node.d.ts +119 -92
  103. package/dist/node.js +3 -3
  104. package/dist/{observability-Ch-VQJyE.js → observability-C-ISCCLE.js} +1247 -326
  105. package/dist/observability-C-ISCCLE.js.map +1 -0
  106. package/dist/observability.d.ts +27 -3
  107. package/dist/observability.js +3 -3
  108. package/dist/path-segment-DBXG26PW.js +363 -0
  109. package/dist/path-segment-DBXG26PW.js.map +1 -0
  110. package/dist/{plan-C4qgiXSg.js → plan-BvQbaNMe.js} +19 -11
  111. package/dist/plan-BvQbaNMe.js.map +1 -0
  112. package/dist/request-CRWiTrza.js +272 -0
  113. package/dist/request-CRWiTrza.js.map +1 -0
  114. package/dist/restore-U6Im8V1V.js +1467 -0
  115. package/dist/restore-U6Im8V1V.js.map +1 -0
  116. package/dist/retry-OBtLB2GC.js +126 -0
  117. package/dist/retry-OBtLB2GC.js.map +1 -0
  118. package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
  119. package/dist/{runtime-spec--LykAdl1.js → runtime-spec-B5mg3pHF.js} +189 -28
  120. package/dist/runtime-spec-B5mg3pHF.js.map +1 -0
  121. package/dist/{s3-http-DD5gDc7t.d.ts → s3-http-DBC_wiCL.d.ts} +14 -8
  122. package/dist/s3.d.ts +20 -7
  123. package/dist/s3.js +4 -5
  124. package/dist/s3.js.map +1 -1
  125. package/dist/{sha256-CqcKTjw9.js → sha256-4FfGQNPw.js} +9 -9
  126. package/dist/sha256-4FfGQNPw.js.map +1 -0
  127. package/dist/{shared-secret-DgEicd3x.js → shared-secret-Vkur-8r0.js} +27 -15
  128. package/dist/shared-secret-Vkur-8r0.js.map +1 -0
  129. package/dist/{aws4fetch.esm-CXE5ZbAa.js → sigv4-sign-5IUflUD_.js} +143 -96
  130. package/dist/sigv4-sign-5IUflUD_.js.map +1 -0
  131. package/dist/snapshot-CknzkDM0.js +148 -0
  132. package/dist/snapshot-CknzkDM0.js.map +1 -0
  133. package/dist/{src-BMFfDUI2.js → src-Actga-bO.js} +949 -363
  134. package/dist/src-Actga-bO.js.map +1 -0
  135. package/dist/src-D0MQfvOp.js +812 -0
  136. package/dist/src-D0MQfvOp.js.map +1 -0
  137. package/dist/src-Dr9uo3dc.js +501 -0
  138. package/dist/src-Dr9uo3dc.js.map +1 -0
  139. package/dist/{subcommand-BV68pqwJ.js → subcommand-BLoF66dG.js} +89 -16
  140. package/dist/subcommand-BLoF66dG.js.map +1 -0
  141. package/dist/{time-DUqvFMHq.js → time-DRxTP9iv.js} +15 -34
  142. package/dist/time-DRxTP9iv.js.map +1 -0
  143. package/dist/types-suVbsEWS.d.ts +116 -0
  144. package/dist/{usage-BMZR8o6U.js → usage-CPzVhrQr.js} +40 -45
  145. package/dist/usage-CPzVhrQr.js.map +1 -0
  146. package/dist/uuid-BuT_c404.js +333 -0
  147. package/dist/uuid-BuT_c404.js.map +1 -0
  148. package/dist/verifier-Bmlmndzo.d.ts +95 -0
  149. package/dist/{wire-izfGZDvr.js → wire-DndvKU-K.js} +2 -3
  150. package/dist/wire-DndvKU-K.js.map +1 -0
  151. package/package.json +90 -69
  152. package/dist/aws4fetch.esm-CXE5ZbAa.js.map +0 -1
  153. package/dist/bytes-BXdamO3L.js +0 -11
  154. package/dist/bytes-BXdamO3L.js.map +0 -1
  155. package/dist/cloudflare-wrVYf4bb.js.map +0 -1
  156. package/dist/config-B6nTy8e2.js +0 -3095
  157. package/dist/config-B6nTy8e2.js.map +0 -1
  158. package/dist/constants-CfeMWQWk.js +0 -222
  159. package/dist/constants-CfeMWQWk.js.map +0 -1
  160. package/dist/context-DRZ3tZ5l.js.map +0 -1
  161. package/dist/cost-_SE_SVgZ.js +0 -203
  162. package/dist/cost-_SE_SVgZ.js.map +0 -1
  163. package/dist/current-json-C6nhPOm1.js.map +0 -1
  164. package/dist/db-DjjthkTi.d.ts +0 -254
  165. package/dist/deploy-Di_Q01qx.js.map +0 -1
  166. package/dist/doctor-RWVRpvat.js +0 -102
  167. package/dist/doctor-RWVRpvat.js.map +0 -1
  168. package/dist/dump-m2vEYDNY.js +0 -94
  169. package/dist/dump-m2vEYDNY.js.map +0 -1
  170. package/dist/errors-Dfa3p78c.js +0 -78
  171. package/dist/errors-Dfa3p78c.js.map +0 -1
  172. package/dist/export-DenKwEQu.js +0 -401
  173. package/dist/export-DenKwEQu.js.map +0 -1
  174. package/dist/fsck-2Vq-7-e2.js +0 -279
  175. package/dist/fsck-2Vq-7-e2.js.map +0 -1
  176. package/dist/goog4-signer-Z7KnJ1su.js.map +0 -1
  177. package/dist/http-7zT29K3P.js.map +0 -1
  178. package/dist/http-transport-BTgVCY5r.js +0 -1250
  179. package/dist/http-transport-BTgVCY5r.js.map +0 -1
  180. package/dist/index-BHz92Acj.d.ts +0 -162
  181. package/dist/index-CEZKQsKt.d.ts +0 -1113
  182. package/dist/index-uE-w2dgj.d.ts +0 -115
  183. package/dist/indexes-Dn9hbGQG.d.ts +0 -22
  184. package/dist/inspect-BpYbH1DM.js +0 -133
  185. package/dist/inspect-BpYbH1DM.js.map +0 -1
  186. package/dist/log-tail-QWU4wlu-.js +0 -514
  187. package/dist/log-tail-QWU4wlu-.js.map +0 -1
  188. package/dist/maintenance-BGHGt2Yg.d.ts +0 -537
  189. package/dist/maintenance-DULFcpd1.js +0 -2144
  190. package/dist/maintenance-DULFcpd1.js.map +0 -1
  191. package/dist/maintenance-fEi-UZ2o.js +0 -1412
  192. package/dist/maintenance-fEi-UZ2o.js.map +0 -1
  193. package/dist/normalize-rjnZLwS4.js +0 -133
  194. package/dist/normalize-rjnZLwS4.js.map +0 -1
  195. package/dist/observability-Ch-VQJyE.js.map +0 -1
  196. package/dist/plan-C4qgiXSg.js.map +0 -1
  197. package/dist/query-C43r-6ib.js +0 -1773
  198. package/dist/query-C43r-6ib.js.map +0 -1
  199. package/dist/rebuild-index-BH1dc1p6.js +0 -81
  200. package/dist/rebuild-index-BH1dc1p6.js.map +0 -1
  201. package/dist/request-u0M51mhJ.js +0 -72
  202. package/dist/request-u0M51mhJ.js.map +0 -1
  203. package/dist/restore-D0VYWzfP.js +0 -778
  204. package/dist/restore-D0VYWzfP.js.map +0 -1
  205. package/dist/rolldown-runtime-EAsCxrDo.js +0 -14
  206. package/dist/runtime-spec--LykAdl1.js.map +0 -1
  207. package/dist/sha256-CqcKTjw9.js.map +0 -1
  208. package/dist/shared-secret-DgEicd3x.js.map +0 -1
  209. package/dist/src-BMFfDUI2.js.map +0 -1
  210. package/dist/src-DYZ4H1aF.js +0 -392
  211. package/dist/src-DYZ4H1aF.js.map +0 -1
  212. package/dist/src-DvbTEya2.js +0 -536
  213. package/dist/src-DvbTEya2.js.map +0 -1
  214. package/dist/subcommand-BV68pqwJ.js.map +0 -1
  215. package/dist/time-DUqvFMHq.js.map +0 -1
  216. package/dist/usage-BMZR8o6U.js.map +0 -1
  217. package/dist/validate-DtljsCh1.js.map +0 -1
  218. package/dist/wire-izfGZDvr.js.map +0 -1
package/dist/baerly.js CHANGED
@@ -1,29 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { parseArgs } from "node:util";
3
- //#region \0rolldown/runtime.js
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
13
- key = keys[i];
14
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
- get: ((k) => from[k]).bind(null, key),
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
- });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
22
- value: mod,
23
- enumerable: true
24
- }) : target, mod));
25
- //#endregion
26
- //#region ../../node_modules/.pnpm/citty@0.2.2/node_modules/citty/dist/_chunks/libs/scule.mjs
2
+ import { parseArgs as parseArgs$1, styleText } from "node:util";
3
+ // ../../node_modules/.pnpm/citty@0.2.2/node_modules/citty/dist/_chunks/libs/scule.mjs
27
4
  const NUMBER_CHAR_RE = /\d/;
28
5
  const STR_SPLITTERS = [
29
6
  "-",
@@ -91,8 +68,7 @@ function kebabCase(str, joiner) {
91
68
  function snakeCase(str) {
92
69
  return kebabCase(str || "", "_");
93
70
  }
94
- //#endregion
95
- //#region ../../node_modules/.pnpm/citty@0.2.2/node_modules/citty/dist/index.mjs
71
+ // ../../node_modules/.pnpm/citty@0.2.2/node_modules/citty/dist/index.mjs
96
72
  function toArray(val) {
97
73
  if (Array.isArray(val)) return val;
98
74
  return val === void 0 ? [] : [val];
@@ -173,7 +149,7 @@ function parseRawArgs(args = [], opts = {}) {
173
149
  }
174
150
  let parsed;
175
151
  try {
176
- parsed = parseArgs({
152
+ parsed = parseArgs$1({
177
153
  args: processedArgs,
178
154
  options: Object.keys(options).length > 0 ? options : void 0,
179
155
  allowPositionals: true,
@@ -216,7 +192,7 @@ const bold = /* @__PURE__ */ _c(1, 22);
216
192
  const cyan = /* @__PURE__ */ _c(36);
217
193
  const gray = /* @__PURE__ */ _c(90);
218
194
  const underline = /* @__PURE__ */ _c(4, 24);
219
- function parseArgs$1(rawArgs, argsDef) {
195
+ function parseArgs(rawArgs, argsDef) {
220
196
  const parseOptions = {
221
197
  boolean: [],
222
198
  string: [],
@@ -240,7 +216,7 @@ function parseArgs$1(rawArgs, argsDef) {
240
216
  }
241
217
  }
242
218
  const parsed = parseRawArgs(rawArgs, parseOptions);
243
- const [ ...positionalArguments] = parsed._;
219
+ const [...positionalArguments] = parsed._;
244
220
  const parsedArgsProxy = new Proxy(parsed, { get(target, prop) {
245
221
  return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
246
222
  } });
@@ -273,7 +249,7 @@ function defineCommand(def) {
273
249
  }
274
250
  async function runCommand(cmd, opts) {
275
251
  const cmdArgs = await resolveValue(cmd.args || {});
276
- const parsedArgs = parseArgs$1(opts.rawArgs, cmdArgs);
252
+ const parsedArgs = parseArgs(opts.rawArgs, cmdArgs);
277
253
  const context = {
278
254
  rawArgs: opts.rawArgs,
279
255
  args: parsedArgs,
@@ -444,15 +420,25 @@ function renderDescription(arg, required) {
444
420
  defaultHint
445
421
  ].filter(Boolean).join(" ");
446
422
  }
447
- //#endregion
448
- //#region ../protocol/src/errors.ts
423
+ // ../protocol/src/errors.ts
424
+ /**
425
+ * Codes whose failure can clear on retry. `BaerlyError.retriable` is
426
+ * exactly membership in this set; there are no per-instance overrides.
427
+ */
428
+ const RETRIABLE_CODES = /* @__PURE__ */ new Set([
429
+ "NetworkError",
430
+ "WriteConflict",
431
+ "MaintenancePending"
432
+ ]);
449
433
  /**
450
- * Codes whose default failure class is resolved by retrying with a fresh read.
451
- * Throw sites may override this when the same code is context-sensitive
452
- * (notably caller-supplied `_id` collisions, which also use `Conflict`).
434
+ * True iff `err` is a `WriteConflict`: a lost conditional write or CAS
435
+ * race. The one predicate every kernel catch site uses, so the code's
436
+ * meaning is tested in one place. Matches on `name` and `code` rather
437
+ * than `instanceof`, so an error from a second loaded copy of this module
438
+ * or another realm still classifies.
453
439
  */
454
- const RETRIABLE_CODES = /* @__PURE__ */ new Set(["NetworkError", "Conflict"]);
455
- /** True iff this error code's default failure class is retriable. */
440
+ const isWriteConflict = (err) => typeof err === "object" && err !== null && err.name === "BaerlyError" && err.code === "WriteConflict";
441
+ /** True iff this error code is retriable (membership in {@link RETRIABLE_CODES}). */
456
442
  const isRetriableCode = (code) => RETRIABLE_CODES.has(code);
457
443
  /**
458
444
  * The single error class thrown by baerly-storage. Discriminate by `code`, not
@@ -465,12 +451,18 @@ const isRetriableCode = (code) => RETRIABLE_CODES.has(code);
465
451
  * @example
466
452
  * ```ts
467
453
  * try {
468
- * await db.collection("tickets").insert({ title: "hi" });
454
+ * await db.collection("tickets").insert({ _id: "t-1", title: "hi" });
469
455
  * } catch (err) {
470
- * if (err instanceof BaerlyError && err.code === "Conflict") {
471
- * // Check err.retriable; CAS can retry, duplicate _id cannot.
456
+ * if (!(err instanceof BaerlyError)) throw err;
457
+ * if (err.code === "AlreadyExists") {
458
+ * // t-1 is taken; retrying cannot succeed.
459
+ * } else if (err.code === "AmbiguousCommit") {
460
+ * // May have landed: re-read err._id before deciding.
461
+ * } else if (err.retriable) {
462
+ * // WriteConflict or NetworkError: retry with bounded backoff.
463
+ * } else {
464
+ * throw err;
472
465
  * }
473
- * throw err;
474
466
  * }
475
467
  * ```
476
468
  */
@@ -489,6 +481,14 @@ var BaerlyError = class extends Error {
489
481
  */
490
482
  issues;
491
483
  /**
484
+ * The `_id` of the row whose commit outcome is unknown, set only when
485
+ * `code === "AmbiguousCommit"`. For an auto-ID insert it is the minted
486
+ * id, so the caller can re-read the row and retry with the same `_id`
487
+ * rather than mint a second document. A missing row does not prove the
488
+ * write failed. The HTTP layer carries it in `HttpErrorEnvelope`.
489
+ */
490
+ _id;
491
+ /**
492
492
  * Raw HTTP status, set only by the client-side wire decoder when
493
493
  * inflating an `HttpErrorEnvelope` into this class. Server-side
494
494
  * throws never set it (the HTTP layer's `mapError` derives the
@@ -500,78 +500,64 @@ var BaerlyError = class extends Error {
500
500
  status;
501
501
  /** Canonical corrective action; crosses the wire via `HttpErrorEnvelope.error.resolution`. */
502
502
  resolution;
503
- retriableOverride;
503
+ /** Suggested delay in seconds before retrying; set only for `MaintenancePending`. Crosses the wire via `HttpErrorEnvelope.error.retryAfter` and the `Retry-After` header. */
504
+ retryAfter;
504
505
  /**
505
- * Whether this error instance is retriable. Defaults from `code`, but
506
- * context-sensitive throw sites can override it.
506
+ * `true` iff re-running the operation from its read step can succeed:
507
+ * `NetworkError` (retry with backoff) and `WriteConflict` (re-read, then
508
+ * write again). A `Collection` / `Query` verb re-reads on every call, so
509
+ * calling it again is the retry; a blind resend of the same conditional
510
+ * `Storage` put loses again. A pure function of `code`
511
+ * ({@link isRetriableCode}): every instance of a code gives the same
512
+ * answer. `AmbiguousCommit` is `false` because the write may have landed;
513
+ * reconcile by `_id` first.
507
514
  */
508
515
  get retriable() {
509
- return this.retriableOverride ?? isRetriableCode(this.code);
516
+ return isRetriableCode(this.code);
510
517
  }
511
- constructor(code, message, cause, issues, status, resolution, retriableOverride) {
518
+ /**
519
+ * `code` and `message` are positional; everything else goes in `options`,
520
+ * as with `new Error(message, { cause })`. Passing an `Error` (or any
521
+ * non-options value) as the third argument does not compile; the
522
+ * options object is where `cause` goes.
523
+ *
524
+ * @example
525
+ * ```ts
526
+ * throw new BaerlyError("NetworkError", "PUT failed", { cause: err });
527
+ * throw new BaerlyError("AmbiguousCommit", "commit outcome unknown", { _id: "t-1" });
528
+ * ```
529
+ */
530
+ constructor(code, message, options) {
512
531
  super(message);
513
532
  this.name = "BaerlyError";
514
533
  this.code = code;
515
- this.cause = cause;
516
- this.retriableOverride = retriableOverride;
534
+ this.cause = options?.cause;
535
+ const { issues, status, resolution, _id, retryAfter } = options ?? {};
517
536
  if (issues !== void 0) this.issues = issues;
518
537
  if (status !== void 0) this.status = status;
519
538
  if (resolution !== void 0) this.resolution = resolution;
539
+ if (_id !== void 0) this._id = _id;
540
+ if (retryAfter !== void 0) this.retryAfter = retryAfter;
520
541
  }
521
542
  };
522
- //#endregion
523
- //#region src/output.ts
524
- var import_picocolors_browser = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
525
- var x = String;
526
- var create = function() {
527
- return {
528
- isColorSupported: false,
529
- reset: x,
530
- bold: x,
531
- dim: x,
532
- italic: x,
533
- underline: x,
534
- inverse: x,
535
- hidden: x,
536
- strikethrough: x,
537
- black: x,
538
- red: x,
539
- green: x,
540
- yellow: x,
541
- blue: x,
542
- magenta: x,
543
- cyan: x,
544
- white: x,
545
- gray: x,
546
- bgBlack: x,
547
- bgRed: x,
548
- bgGreen: x,
549
- bgYellow: x,
550
- bgBlue: x,
551
- bgMagenta: x,
552
- bgCyan: x,
553
- bgWhite: x,
554
- blackBright: x,
555
- redBright: x,
556
- greenBright: x,
557
- yellowBright: x,
558
- blueBright: x,
559
- magentaBright: x,
560
- cyanBright: x,
561
- whiteBright: x,
562
- bgBlackBright: x,
563
- bgRedBright: x,
564
- bgGreenBright: x,
565
- bgYellowBright: x,
566
- bgBlueBright: x,
567
- bgMagentaBright: x,
568
- bgCyanBright: x,
569
- bgWhiteBright: x
570
- };
571
- };
572
- module.exports = create();
573
- module.exports.createColors = create;
574
- })))(), 1);
543
+ // src/output.ts
544
+ /**
545
+ * Output contract for `baerly`. Two modes:
546
+ *
547
+ * - text (default): preserves the legacy `baerly <cmd>: <code>:
548
+ * <msg>\n` shape on stderr (asserted by `copy.test.ts`); stdout
549
+ * stays silent on success.
550
+ * - JSON (`--json`): one structured envelope per invocation —
551
+ * `{result,...}` on stdout for success, `{error:{code,message,
552
+ * command}}` on stderr for failure. Picked up by agents that
553
+ * drive the CLI programmatically.
554
+ *
555
+ * Detection of `--json` happens twice — once in `baerly.ts` before
556
+ * `runMain` (so a parse-time error from citty also honors the flag)
557
+ * and once inside each subcommand's `run` handler (so programmatic
558
+ * `runCopy` callers like `copy.test.ts` work without going through
559
+ * the entry).
560
+ */
575
561
  let jsonMode = false;
576
562
  /** Toggle JSON-envelope output mode. Called from `baerly.ts` and each subcommand. */
577
563
  const setJsonMode = (v) => {
@@ -580,13 +566,13 @@ const setJsonMode = (v) => {
580
566
  const isJsonMode = () => jsonMode;
581
567
  /**
582
568
  * Color helpers — no-ops in JSON mode (so emitted JSON stays
583
- * machine-parseable) and when `picocolors` detects a non-TTY or
569
+ * machine-parseable) and when `util.styleText` detects a non-TTY or
584
570
  * `NO_COLOR`.
585
571
  */
586
572
  const color = {
587
- red: (s) => jsonMode ? s : import_picocolors_browser.default.red(s),
588
- yellow: (s) => jsonMode ? s : import_picocolors_browser.default.yellow(s),
589
- dim: (s) => jsonMode ? s : import_picocolors_browser.default.dim(s)
573
+ red: (s) => jsonMode ? s : styleText("red", s),
574
+ yellow: (s) => jsonMode ? s : styleText("yellow", s),
575
+ dim: (s) => jsonMode ? s : styleText("dim", s)
590
576
  };
591
577
  /**
592
578
  * Emit an error. Text mode preserves the legacy `baerly <cmd>:
@@ -628,8 +614,13 @@ const emitError = (command, code, message) => {
628
614
  const emitSuccess = (data) => {
629
615
  if (jsonMode) process.stdout.write(`${JSON.stringify({ result: data })}\n`);
630
616
  };
631
- //#endregion
632
- //#region src/bin-runner.ts
617
+ /** Shared exit-code mapping for caught `BaerlyError`s. */
618
+ const errorToExitCode = (code) => {
619
+ if (code === "InvalidConfig") return 1;
620
+ if (code === "WriteConflict" || code === "AlreadyExists" || code === "Internal" || code === "InvalidResponse" || code === "AmbiguousCommit") return 3;
621
+ return 2;
622
+ };
623
+ // src/bin-runner.ts
633
624
  /**
634
625
  * `runBin` — bin-entry shim around citty 0.2.2's `runCommand`.
635
626
  *
@@ -657,13 +648,8 @@ const emitSuccess = (data) => {
657
648
  * …)` semantics.
658
649
  * - Maps `BaerlyError.code` through the same 3-bucket exit-code
659
650
  * table the per-subcommand wrappers use (`InvalidConfig → 1`,
660
- * `Conflict|Internal|InvalidResponse → 3`, else 2).
651
+ * `WriteConflict|AlreadyExists|Internal|InvalidResponse|AmbiguousCommit → 3`, else 2).
661
652
  */
662
- const errorToExitCode = (code) => {
663
- if (code === "InvalidConfig") return 1;
664
- if (code === "Conflict" || code === "Internal" || code === "InvalidResponse") return 3;
665
- return 2;
666
- };
667
653
  const resolve = async (v) => {
668
654
  if (typeof v === "function") return v();
669
655
  return v;
@@ -726,12 +712,14 @@ const runBin = async (cmd, argv, brand = "baerly") => {
726
712
  emitError(brand, error.code, error.message);
727
713
  process.exit(errorToExitCode(error.code));
728
714
  }
729
- emitError(brand, "InvalidConfig", error instanceof Error ? error.message : String(error));
715
+ const message = error instanceof Error ? error.message : String(error);
716
+ emitError(brand, "InvalidConfig", message);
730
717
  process.exit(1);
731
718
  }
732
719
  };
733
- //#endregion
734
- //#region src/baerly.ts
720
+ // ../../package.json
721
+ var version = "0.7.0";
722
+ // src/baerly.ts
735
723
  /**
736
724
  * `baerly` — vendorless document database CLI. Entry point bundled
737
725
  * to `dist/baerly.js` by `rolldown.config.ts` with a `#!/usr/bin/env
@@ -748,34 +736,38 @@ const runBin = async (cmd, argv, brand = "baerly") => {
748
736
  * Exit codes are documented in `packages/cli/README.md` and per-
749
737
  * subcommand in each module's docstring.
750
738
  */
739
+ /**
740
+ * `baerly admin <command>` — operator-side reconciliation, inspection,
741
+ * data-shovel, and maintenance tools. Today: `dump`, `restore`,
742
+ * `fsck`, `usage`.
743
+ */
744
+ const admin = defineCommand({
745
+ meta: {
746
+ name: "admin",
747
+ description: "Operator commands — reconciliation and inspection."
748
+ },
749
+ subCommands: {
750
+ dump: () => import("./dump-D1vX8ozg.js").then((m) => m.dumpCmd),
751
+ restore: () => import("./restore-U6Im8V1V.js").then((m) => m.restoreCmd),
752
+ fsck: () => import("./fsck-BWkPgov4.js").then((m) => m.fsckCmd),
753
+ usage: () => import("./usage-CPzVhrQr.js").then((m) => m.usageCmd)
754
+ }
755
+ });
751
756
  runBin(defineCommand({
752
757
  meta: {
753
758
  name: "baerly",
754
- version: "0.0.0",
759
+ version,
755
760
  description: "Vendorless document database CLI."
756
761
  },
757
762
  subCommands: {
758
- deploy: () => import("./deploy-Di_Q01qx.js").then((m) => m.deploy),
759
- doctor: () => import("./doctor-RWVRpvat.js").then((m) => m.doctor),
760
- inspect: () => import("./inspect-BpYbH1DM.js").then((m) => m.inspect),
761
- export: () => import("./export-DenKwEQu.js").then((m) => m.exportCmd),
762
- cost: () => import("./cost-_SE_SVgZ.js").then((m) => m.cost),
763
- admin: defineCommand({
764
- meta: {
765
- name: "admin",
766
- description: "Operator commands — reconciliation and inspection."
767
- },
768
- subCommands: {
769
- "rebuild-index": () => import("./rebuild-index-BH1dc1p6.js").then((m) => m.rebuildIndexCmd),
770
- dump: () => import("./dump-m2vEYDNY.js").then((m) => m.dumpCmd),
771
- restore: () => import("./restore-D0VYWzfP.js").then((m) => m.restoreCmd),
772
- fsck: () => import("./fsck-2Vq-7-e2.js").then((m) => m.fsckCmd),
773
- usage: () => import("./usage-BMZR8o6U.js").then((m) => m.usageCmd)
774
- }
775
- })
763
+ deploy: () => import("./deploy-Obj4nE-Z.js").then((m) => m.deploy),
764
+ doctor: () => import("./doctor-BA0i-YAN.js").then((m) => m.doctor),
765
+ inspect: () => import("./inspect-BTsVYZKd.js").then((m) => m.inspect),
766
+ export: () => import("./export-BVL2EvYE.js").then((m) => m.exportCmd),
767
+ cost: () => import("./cost-B52llVDx.js").then((m) => m.cost),
768
+ admin
776
769
  }
777
770
  }), process.argv.slice(2), "baerly");
778
- //#endregion
779
- export { setJsonMode as a, parseArgs$1 as c, isJsonMode as i, __commonJSMin as l, emitError as n, BaerlyError as o, emitSuccess as r, defineCommand as s, color as t };
771
+ export { isJsonMode as a, isWriteConflict as c, errorToExitCode as i, defineCommand as l, emitError as n, setJsonMode as o, emitSuccess as r, BaerlyError as s, color as t, parseArgs as u };
780
772
 
781
773
  //# sourceMappingURL=baerly.js.map