@gusto/baerly-storage 0.1.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 (115) hide show
  1. package/README.md +97 -0
  2. package/dist/API.md +850 -0
  3. package/dist/app-config-Cb5dO2s9.d.ts +480 -0
  4. package/dist/app-config.d.ts +2 -0
  5. package/dist/app-config.js +8 -0
  6. package/dist/app-config.js.map +1 -0
  7. package/dist/auth.d.ts +237 -0
  8. package/dist/auth.js +1335 -0
  9. package/dist/auth.js.map +1 -0
  10. package/dist/baerly.js +761 -0
  11. package/dist/baerly.js.map +1 -0
  12. package/dist/bucket-uri-BrDEYvzy.js +4922 -0
  13. package/dist/bucket-uri-BrDEYvzy.js.map +1 -0
  14. package/dist/chunk-EAsCxrDo.js +14 -0
  15. package/dist/client-BLf3Ae5s.d.ts +233 -0
  16. package/dist/client-react.d.ts +131 -0
  17. package/dist/client-react.js +559 -0
  18. package/dist/client-react.js.map +1 -0
  19. package/dist/client.d.ts +4 -0
  20. package/dist/client.js +160 -0
  21. package/dist/client.js.map +1 -0
  22. package/dist/cloudflare-CINJPKCW.js +911 -0
  23. package/dist/cloudflare-CINJPKCW.js.map +1 -0
  24. package/dist/cloudflare.d.ts +211 -0
  25. package/dist/cloudflare.js +445 -0
  26. package/dist/cloudflare.js.map +1 -0
  27. package/dist/config-Bsg8wgwo.js +198 -0
  28. package/dist/config-Bsg8wgwo.js.map +1 -0
  29. package/dist/context-Oj7ffwD-.js +187 -0
  30. package/dist/context-Oj7ffwD-.js.map +1 -0
  31. package/dist/cost-B1WiZxlf.js +203 -0
  32. package/dist/cost-B1WiZxlf.js.map +1 -0
  33. package/dist/current-json-BkatBzF7.js +252 -0
  34. package/dist/current-json-BkatBzF7.js.map +1 -0
  35. package/dist/db-D62JguBc.d.ts +336 -0
  36. package/dist/deploy-BB-wqbhf.js +83 -0
  37. package/dist/deploy-BB-wqbhf.js.map +1 -0
  38. package/dist/dev-banner-CWHIk8tH.d.ts +26 -0
  39. package/dist/dev-vite.d.ts +146 -0
  40. package/dist/dev-vite.js +223 -0
  41. package/dist/dev-vite.js.map +1 -0
  42. package/dist/dev.d.ts +3 -0
  43. package/dist/dev.js +2 -0
  44. package/dist/doctor-B8h9GCN9.js +331 -0
  45. package/dist/doctor-B8h9GCN9.js.map +1 -0
  46. package/dist/dump-BHo_sIMZ.js +116 -0
  47. package/dist/dump-BHo_sIMZ.js.map +1 -0
  48. package/dist/errors-DOdL95kK.js +58 -0
  49. package/dist/errors-DOdL95kK.js.map +1 -0
  50. package/dist/export-Dz2PZKSR.js +423 -0
  51. package/dist/export-Dz2PZKSR.js.map +1 -0
  52. package/dist/fsck-DEz9lyCy.js +293 -0
  53. package/dist/fsck-DEz9lyCy.js.map +1 -0
  54. package/dist/http-CjUO1Bec.js +1756 -0
  55. package/dist/http-CjUO1Bec.js.map +1 -0
  56. package/dist/http.d.ts +1619 -0
  57. package/dist/http.js +2 -0
  58. package/dist/index-BGC-ENnj.d.ts +1065 -0
  59. package/dist/index-BYv0hb8M.d.ts +1457 -0
  60. package/dist/index-BquQkhJi.d.ts +112 -0
  61. package/dist/index-COsQ-Mlz.d.ts +146 -0
  62. package/dist/index.d.ts +6 -0
  63. package/dist/index.js +6 -0
  64. package/dist/indexes-BXn7a06a.js +297 -0
  65. package/dist/indexes-BXn7a06a.js.map +1 -0
  66. package/dist/indexes-DwOXkn1Y.d.ts +22 -0
  67. package/dist/inspect-x02aFWnh.js +149 -0
  68. package/dist/inspect-x02aFWnh.js.map +1 -0
  69. package/dist/log-walk-DIru96UT.js +260 -0
  70. package/dist/log-walk-DIru96UT.js.map +1 -0
  71. package/dist/maintenance-Bn6ul9aV.js +758 -0
  72. package/dist/maintenance-Bn6ul9aV.js.map +1 -0
  73. package/dist/maintenance.d.ts +323 -0
  74. package/dist/maintenance.js +2 -0
  75. package/dist/node.d.ts +422 -0
  76. package/dist/node.js +2 -0
  77. package/dist/normalize-XWY25_sG.js +133 -0
  78. package/dist/normalize-XWY25_sG.js.map +1 -0
  79. package/dist/observability-2IDYRuZK.js +2333 -0
  80. package/dist/observability-2IDYRuZK.js.map +1 -0
  81. package/dist/observability.d.ts +3 -0
  82. package/dist/observability.js +3 -0
  83. package/dist/plan-Cs17VqjU.js +224 -0
  84. package/dist/plan-Cs17VqjU.js.map +1 -0
  85. package/dist/query-DcSbFLJt.js +1880 -0
  86. package/dist/query-DcSbFLJt.js.map +1 -0
  87. package/dist/rebuild-index-C5gTXryd.js +119 -0
  88. package/dist/rebuild-index-C5gTXryd.js.map +1 -0
  89. package/dist/rebuild-index-DwXM0WfA.js +104 -0
  90. package/dist/rebuild-index-DwXM0WfA.js.map +1 -0
  91. package/dist/request-BEF_OvMh.js +72 -0
  92. package/dist/request-BEF_OvMh.js.map +1 -0
  93. package/dist/restore-CbKVMMpm.js +847 -0
  94. package/dist/restore-CbKVMMpm.js.map +1 -0
  95. package/dist/shared-secret-BJdSwpgw.js +71 -0
  96. package/dist/shared-secret-BJdSwpgw.js.map +1 -0
  97. package/dist/snapshot-D7C4_FSl.js +71 -0
  98. package/dist/snapshot-D7C4_FSl.js.map +1 -0
  99. package/dist/snapshot-z_N9hpTe.js +917 -0
  100. package/dist/snapshot-z_N9hpTe.js.map +1 -0
  101. package/dist/src-Chafbw8r.js +522 -0
  102. package/dist/src-Chafbw8r.js.map +1 -0
  103. package/dist/src-DyET_VPP.js +6199 -0
  104. package/dist/src-DyET_VPP.js.map +1 -0
  105. package/dist/src-n0Te1r98.js +352 -0
  106. package/dist/src-n0Te1r98.js.map +1 -0
  107. package/dist/subcommand-BWs6K7zb.js +110 -0
  108. package/dist/subcommand-BWs6K7zb.js.map +1 -0
  109. package/dist/usage-RVUQMLop.js +339 -0
  110. package/dist/usage-RVUQMLop.js.map +1 -0
  111. package/dist/validate-DhH1lO8I.js +377 -0
  112. package/dist/validate-DhH1lO8I.js.map +1 -0
  113. package/dist/wire-izfGZDvr.js +7 -0
  114. package/dist/wire-izfGZDvr.js.map +1 -0
  115. package/package.json +189 -0
package/dist/baerly.js ADDED
@@ -0,0 +1,761 @@
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
27
+ const NUMBER_CHAR_RE = /\d/;
28
+ const STR_SPLITTERS = [
29
+ "-",
30
+ "_",
31
+ "/",
32
+ "."
33
+ ];
34
+ function isUppercase(char = "") {
35
+ if (NUMBER_CHAR_RE.test(char)) return;
36
+ return char !== char.toLowerCase();
37
+ }
38
+ function splitByCase(str, separators) {
39
+ const splitters = separators ?? STR_SPLITTERS;
40
+ const parts = [];
41
+ if (!str || typeof str !== "string") return parts;
42
+ let buff = "";
43
+ let previousUpper;
44
+ let previousSplitter;
45
+ for (const char of str) {
46
+ const isSplitter = splitters.includes(char);
47
+ if (isSplitter === true) {
48
+ parts.push(buff);
49
+ buff = "";
50
+ previousUpper = void 0;
51
+ continue;
52
+ }
53
+ const isUpper = isUppercase(char);
54
+ if (previousSplitter === false) {
55
+ if (previousUpper === false && isUpper === true) {
56
+ parts.push(buff);
57
+ buff = char;
58
+ previousUpper = isUpper;
59
+ continue;
60
+ }
61
+ if (previousUpper === true && isUpper === false && buff.length > 1) {
62
+ const lastChar = buff.at(-1);
63
+ parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
64
+ buff = lastChar + char;
65
+ previousUpper = isUpper;
66
+ continue;
67
+ }
68
+ }
69
+ buff += char;
70
+ previousUpper = isUpper;
71
+ previousSplitter = isSplitter;
72
+ }
73
+ parts.push(buff);
74
+ return parts;
75
+ }
76
+ function upperFirst(str) {
77
+ return str ? str[0].toUpperCase() + str.slice(1) : "";
78
+ }
79
+ function lowerFirst(str) {
80
+ return str ? str[0].toLowerCase() + str.slice(1) : "";
81
+ }
82
+ function pascalCase(str, opts) {
83
+ return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
84
+ }
85
+ function camelCase(str, opts) {
86
+ return lowerFirst(pascalCase(str || "", opts));
87
+ }
88
+ function kebabCase(str, joiner) {
89
+ return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
90
+ }
91
+ function snakeCase(str) {
92
+ return kebabCase(str || "", "_");
93
+ }
94
+ //#endregion
95
+ //#region ../../node_modules/.pnpm/citty@0.2.2/node_modules/citty/dist/index.mjs
96
+ function toArray(val) {
97
+ if (Array.isArray(val)) return val;
98
+ return val === void 0 ? [] : [val];
99
+ }
100
+ function formatLineColumns(lines, linePrefix = "") {
101
+ const maxLength = [];
102
+ for (const line of lines) for (const [i, element] of line.entries()) maxLength[i] = Math.max(maxLength[i] || 0, element.length);
103
+ return lines.map((l) => l.map((c, i) => linePrefix + c[i === 0 ? "padStart" : "padEnd"](maxLength[i])).join(" ")).join("\n");
104
+ }
105
+ function resolveValue(input) {
106
+ return typeof input === "function" ? input() : input;
107
+ }
108
+ var CLIError = class extends Error {
109
+ code;
110
+ constructor(message, code) {
111
+ super(message);
112
+ this.name = "CLIError";
113
+ this.code = code;
114
+ }
115
+ };
116
+ function parseRawArgs(args = [], opts = {}) {
117
+ const booleans = new Set(opts.boolean || []);
118
+ const strings = new Set(opts.string || []);
119
+ const aliasMap = opts.alias || {};
120
+ const defaults = opts.default || {};
121
+ const aliasToMain = /* @__PURE__ */ new Map();
122
+ const mainToAliases = /* @__PURE__ */ new Map();
123
+ for (const [key, value] of Object.entries(aliasMap)) {
124
+ const targets = value;
125
+ for (const target of targets) {
126
+ aliasToMain.set(key, target);
127
+ if (!mainToAliases.has(target)) mainToAliases.set(target, []);
128
+ mainToAliases.get(target).push(key);
129
+ aliasToMain.set(target, key);
130
+ if (!mainToAliases.has(key)) mainToAliases.set(key, []);
131
+ mainToAliases.get(key).push(target);
132
+ }
133
+ }
134
+ const options = {};
135
+ function getType(name) {
136
+ if (booleans.has(name)) return "boolean";
137
+ const aliases = mainToAliases.get(name) || [];
138
+ for (const alias of aliases) if (booleans.has(alias)) return "boolean";
139
+ return "string";
140
+ }
141
+ function isStringType(name) {
142
+ if (strings.has(name)) return true;
143
+ const aliases = mainToAliases.get(name) || [];
144
+ for (const alias of aliases) if (strings.has(alias)) return true;
145
+ return false;
146
+ }
147
+ const allOptions = new Set([
148
+ ...booleans,
149
+ ...strings,
150
+ ...Object.keys(aliasMap),
151
+ ...Object.values(aliasMap).flat(),
152
+ ...Object.keys(defaults)
153
+ ]);
154
+ for (const name of allOptions) if (!options[name]) options[name] = {
155
+ type: getType(name),
156
+ default: defaults[name]
157
+ };
158
+ for (const [alias, main] of aliasToMain.entries()) if (alias.length === 1 && options[main] && !options[main].short) options[main].short = alias;
159
+ const processedArgs = [];
160
+ const negatedFlags = {};
161
+ for (let i = 0; i < args.length; i++) {
162
+ const arg = args[i];
163
+ if (arg === "--") {
164
+ processedArgs.push(...args.slice(i));
165
+ break;
166
+ }
167
+ if (arg.startsWith("--no-")) {
168
+ const flagName = arg.slice(5);
169
+ negatedFlags[flagName] = true;
170
+ continue;
171
+ }
172
+ processedArgs.push(arg);
173
+ }
174
+ let parsed;
175
+ try {
176
+ parsed = parseArgs({
177
+ args: processedArgs,
178
+ options: Object.keys(options).length > 0 ? options : void 0,
179
+ allowPositionals: true,
180
+ strict: false
181
+ });
182
+ } catch {
183
+ parsed = {
184
+ values: {},
185
+ positionals: processedArgs
186
+ };
187
+ }
188
+ const out = { _: [] };
189
+ out._ = parsed.positionals;
190
+ for (const [key, value] of Object.entries(parsed.values)) {
191
+ let coerced = value;
192
+ if (getType(key) === "boolean" && typeof value === "string") coerced = value !== "false";
193
+ else if (isStringType(key) && typeof value === "boolean") coerced = "";
194
+ out[key] = coerced;
195
+ }
196
+ for (const [name] of Object.entries(negatedFlags)) {
197
+ out[name] = false;
198
+ const mainName = aliasToMain.get(name);
199
+ if (mainName) out[mainName] = false;
200
+ const aliases = mainToAliases.get(name);
201
+ if (aliases) for (const alias of aliases) out[alias] = false;
202
+ }
203
+ for (const [alias, main] of aliasToMain.entries()) {
204
+ if (out[alias] !== void 0 && out[main] === void 0) out[main] = out[alias];
205
+ if (out[main] !== void 0 && out[alias] === void 0) out[alias] = out[main];
206
+ if (out[alias] !== out[main] && defaults[main] === out[main]) out[main] = out[alias];
207
+ }
208
+ return out;
209
+ }
210
+ const noColor = /* @__PURE__ */ (() => {
211
+ const env = globalThis.process?.env ?? {};
212
+ return env.NO_COLOR === "1" || env.TERM === "dumb" || env.TEST || env.CI;
213
+ })();
214
+ const _c = (c, r = 39) => (t) => noColor ? t : `\u001B[${c}m${t}\u001B[${r}m`;
215
+ const bold = /* @__PURE__ */ _c(1, 22);
216
+ const cyan = /* @__PURE__ */ _c(36);
217
+ const gray = /* @__PURE__ */ _c(90);
218
+ const underline = /* @__PURE__ */ _c(4, 24);
219
+ function parseArgs$1(rawArgs, argsDef) {
220
+ const parseOptions = {
221
+ boolean: [],
222
+ string: [],
223
+ alias: {},
224
+ default: {}
225
+ };
226
+ const args = resolveArgs(argsDef);
227
+ for (const arg of args) {
228
+ if (arg.type === "positional") continue;
229
+ if (arg.type === "string" || arg.type === "enum") parseOptions.string.push(arg.name);
230
+ else if (arg.type === "boolean") parseOptions.boolean.push(arg.name);
231
+ if (arg.default !== void 0) parseOptions.default[arg.name] = arg.default;
232
+ if (arg.alias) parseOptions.alias[arg.name] = arg.alias;
233
+ const camelName = camelCase(arg.name);
234
+ const kebabName = kebabCase(arg.name);
235
+ if (camelName !== arg.name || kebabName !== arg.name) {
236
+ const existingAliases = toArray(parseOptions.alias[arg.name] || []);
237
+ if (camelName !== arg.name && !existingAliases.includes(camelName)) existingAliases.push(camelName);
238
+ if (kebabName !== arg.name && !existingAliases.includes(kebabName)) existingAliases.push(kebabName);
239
+ if (existingAliases.length > 0) parseOptions.alias[arg.name] = existingAliases;
240
+ }
241
+ }
242
+ const parsed = parseRawArgs(rawArgs, parseOptions);
243
+ const [ ...positionalArguments] = parsed._;
244
+ const parsedArgsProxy = new Proxy(parsed, { get(target, prop) {
245
+ return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
246
+ } });
247
+ for (const [, arg] of args.entries()) if (arg.type === "positional") {
248
+ const nextPositionalArgument = positionalArguments.shift();
249
+ if (nextPositionalArgument !== void 0) parsedArgsProxy[arg.name] = nextPositionalArgument;
250
+ else if (arg.default === void 0 && arg.required !== false) throw new CLIError(`Missing required positional argument: ${arg.name.toUpperCase()}`, "EARG");
251
+ else parsedArgsProxy[arg.name] = arg.default;
252
+ } else if (arg.type === "enum") {
253
+ const argument = parsedArgsProxy[arg.name];
254
+ const options = arg.options || [];
255
+ if (argument !== void 0 && options.length > 0 && !options.includes(argument)) throw new CLIError(`Invalid value for argument: ${cyan(`--${arg.name}`)} (${cyan(argument)}). Expected one of: ${options.map((o) => cyan(o)).join(", ")}.`, "EARG");
256
+ } else if (arg.required && parsedArgsProxy[arg.name] === void 0) throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
257
+ return parsedArgsProxy;
258
+ }
259
+ function resolveArgs(argsDef) {
260
+ const args = [];
261
+ for (const [name, argDef] of Object.entries(argsDef || {})) args.push({
262
+ ...argDef,
263
+ name,
264
+ alias: toArray(argDef.alias)
265
+ });
266
+ return args;
267
+ }
268
+ async function resolvePlugins(plugins) {
269
+ return Promise.all(plugins.map((p) => resolveValue(p)));
270
+ }
271
+ function defineCommand(def) {
272
+ return def;
273
+ }
274
+ async function runCommand(cmd, opts) {
275
+ const cmdArgs = await resolveValue(cmd.args || {});
276
+ const parsedArgs = parseArgs$1(opts.rawArgs, cmdArgs);
277
+ const context = {
278
+ rawArgs: opts.rawArgs,
279
+ args: parsedArgs,
280
+ data: opts.data,
281
+ cmd
282
+ };
283
+ const plugins = await resolvePlugins(cmd.plugins ?? []);
284
+ let result;
285
+ let runError;
286
+ try {
287
+ for (const plugin of plugins) await plugin.setup?.(context);
288
+ if (typeof cmd.setup === "function") await cmd.setup(context);
289
+ const subCommands = await resolveValue(cmd.subCommands);
290
+ if (subCommands && Object.keys(subCommands).length > 0) {
291
+ const subCommandArgIndex = findSubCommandIndex(opts.rawArgs, cmdArgs);
292
+ const explicitName = opts.rawArgs[subCommandArgIndex];
293
+ if (explicitName) {
294
+ const subCommand = await _findSubCommand(subCommands, explicitName);
295
+ if (!subCommand) throw new CLIError(`Unknown command ${cyan(explicitName)}`, "E_UNKNOWN_COMMAND");
296
+ await runCommand(subCommand, { rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1) });
297
+ } else {
298
+ const defaultSubCommand = await resolveValue(cmd.default);
299
+ if (defaultSubCommand) {
300
+ if (cmd.run) throw new CLIError(`Cannot specify both 'run' and 'default' on the same command.`, "E_DEFAULT_CONFLICT");
301
+ const subCommand = await _findSubCommand(subCommands, defaultSubCommand);
302
+ if (!subCommand) throw new CLIError(`Default sub command ${cyan(defaultSubCommand)} not found in subCommands.`, "E_UNKNOWN_COMMAND");
303
+ await runCommand(subCommand, { rawArgs: opts.rawArgs });
304
+ } else if (!cmd.run) throw new CLIError(`No command specified.`, "E_NO_COMMAND");
305
+ }
306
+ }
307
+ if (typeof cmd.run === "function") result = await cmd.run(context);
308
+ } catch (error) {
309
+ runError = error;
310
+ }
311
+ const cleanupErrors = [];
312
+ if (typeof cmd.cleanup === "function") try {
313
+ await cmd.cleanup(context);
314
+ } catch (error) {
315
+ cleanupErrors.push(error);
316
+ }
317
+ for (const plugin of [...plugins].reverse()) try {
318
+ await plugin.cleanup?.(context);
319
+ } catch (error) {
320
+ cleanupErrors.push(error);
321
+ }
322
+ if (runError) throw runError;
323
+ if (cleanupErrors.length === 1) throw cleanupErrors[0];
324
+ if (cleanupErrors.length > 1) throw new Error("Multiple cleanup errors", { cause: cleanupErrors });
325
+ return { result };
326
+ }
327
+ async function _findSubCommand(subCommands, name) {
328
+ if (name in subCommands) return resolveValue(subCommands[name]);
329
+ for (const sub of Object.values(subCommands)) {
330
+ const resolved = await resolveValue(sub);
331
+ const meta = await resolveValue(resolved?.meta);
332
+ if (meta?.alias) {
333
+ if (toArray(meta.alias).includes(name)) return resolved;
334
+ }
335
+ }
336
+ }
337
+ function findSubCommandIndex(rawArgs, argsDef) {
338
+ for (let i = 0; i < rawArgs.length; i++) {
339
+ const arg = rawArgs[i];
340
+ if (arg === "--") return -1;
341
+ if (arg.startsWith("-")) {
342
+ if (!arg.includes("=") && _isValueFlag(arg, argsDef)) i++;
343
+ continue;
344
+ }
345
+ return i;
346
+ }
347
+ return -1;
348
+ }
349
+ function _isValueFlag(flag, argsDef) {
350
+ const name = flag.replace(/^-{1,2}/, "");
351
+ const normalized = camelCase(name);
352
+ for (const [key, def] of Object.entries(argsDef)) {
353
+ if (def.type !== "string" && def.type !== "enum") continue;
354
+ if (normalized === camelCase(key)) return true;
355
+ if ((Array.isArray(def.alias) ? def.alias : def.alias ? [def.alias] : []).includes(name)) return true;
356
+ }
357
+ return false;
358
+ }
359
+ async function showUsage(cmd, parent) {
360
+ try {
361
+ console.log(await renderUsage(cmd, parent) + "\n");
362
+ } catch (error) {
363
+ console.error(error);
364
+ }
365
+ }
366
+ const negativePrefixRe = /^no[-A-Z]/;
367
+ async function renderUsage(cmd, parent) {
368
+ const cmdMeta = await resolveValue(cmd.meta || {});
369
+ const cmdArgs = resolveArgs(await resolveValue(cmd.args || {}));
370
+ const parentMeta = await resolveValue(parent?.meta || {});
371
+ const commandName = `${parentMeta.name ? `${parentMeta.name} ` : ""}` + (cmdMeta.name || process.argv[1]);
372
+ const argLines = [];
373
+ const posLines = [];
374
+ const commandsLines = [];
375
+ const usageLine = [];
376
+ for (const arg of cmdArgs) if (arg.type === "positional") {
377
+ const name = arg.name.toUpperCase();
378
+ const isRequired = arg.required !== false && arg.default === void 0;
379
+ posLines.push([cyan(name + renderValueHint(arg)), renderDescription(arg, isRequired)]);
380
+ usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
381
+ } else {
382
+ const isRequired = arg.required === true && arg.default === void 0;
383
+ const argStr = [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(", ") + renderValueHint(arg);
384
+ argLines.push([cyan(argStr), renderDescription(arg, isRequired)]);
385
+ /**
386
+ * print negative boolean arg variant usage when
387
+ * - enabled by default or has `negativeDescription`
388
+ * - not prefixed with `no-` or `no[A-Z]`
389
+ */
390
+ if (arg.type === "boolean" && (arg.default === true || arg.negativeDescription) && !negativePrefixRe.test(arg.name)) {
391
+ const negativeArgStr = [...(arg.alias || []).map((a) => `--no-${a}`), `--no-${arg.name}`].join(", ");
392
+ argLines.push([cyan(negativeArgStr), [arg.negativeDescription, isRequired ? gray("(Required)") : ""].filter(Boolean).join(" ")]);
393
+ }
394
+ if (isRequired) usageLine.push(`--${arg.name}` + renderValueHint(arg));
395
+ }
396
+ if (cmd.subCommands) {
397
+ const commandNames = [];
398
+ const subCommands = await resolveValue(cmd.subCommands);
399
+ for (const [name, sub] of Object.entries(subCommands)) {
400
+ const meta = await resolveValue((await resolveValue(sub))?.meta);
401
+ if (meta?.hidden) continue;
402
+ const aliases = toArray(meta?.alias);
403
+ const label = [name, ...aliases].join(", ");
404
+ commandsLines.push([cyan(label), meta?.description || ""]);
405
+ commandNames.push(name, ...aliases);
406
+ }
407
+ usageLine.push(commandNames.join("|"));
408
+ }
409
+ const usageLines = [];
410
+ const version = cmdMeta.version || parentMeta.version;
411
+ usageLines.push(gray(`${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`), "");
412
+ const hasOptions = argLines.length > 0 || posLines.length > 0;
413
+ usageLines.push(`${underline(bold("USAGE"))} ${cyan(`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}`)}`, "");
414
+ if (posLines.length > 0) {
415
+ usageLines.push(underline(bold("ARGUMENTS")), "");
416
+ usageLines.push(formatLineColumns(posLines, " "));
417
+ usageLines.push("");
418
+ }
419
+ if (argLines.length > 0) {
420
+ usageLines.push(underline(bold("OPTIONS")), "");
421
+ usageLines.push(formatLineColumns(argLines, " "));
422
+ usageLines.push("");
423
+ }
424
+ if (commandsLines.length > 0) {
425
+ usageLines.push(underline(bold("COMMANDS")), "");
426
+ usageLines.push(formatLineColumns(commandsLines, " "));
427
+ usageLines.push("", `Use ${cyan(`${commandName} <command> --help`)} for more information about a command.`);
428
+ }
429
+ return usageLines.filter((l) => typeof l === "string").join("\n");
430
+ }
431
+ function renderValueHint(arg) {
432
+ const valueHint = arg.valueHint ? `=<${arg.valueHint}>` : "";
433
+ const fallbackValueHint = valueHint || `=<${snakeCase(arg.name)}>`;
434
+ if (!arg.type || arg.type === "positional" || arg.type === "boolean") return valueHint;
435
+ if (arg.type === "enum" && arg.options?.length) return `=<${arg.options.join("|")}>`;
436
+ return fallbackValueHint;
437
+ }
438
+ function renderDescription(arg, required) {
439
+ const requiredHint = required ? gray("(Required)") : "";
440
+ const defaultHint = arg.default === void 0 ? "" : gray(`(Default: ${arg.default})`);
441
+ return [
442
+ arg.description,
443
+ requiredHint,
444
+ defaultHint
445
+ ].filter(Boolean).join(" ");
446
+ }
447
+ //#endregion
448
+ //#region ../protocol/src/errors.ts
449
+ /**
450
+ * The single error class thrown by Baerly. Discriminate by `code`, not
451
+ * `instanceof`: the code string survives `JSON.stringify` round-trips
452
+ * across Worker / iframe / postMessage realm boundaries, where each
453
+ * realm has its own `BaerlyError` constructor identity. IDB-restored
454
+ * writes can replay across realms, so `instanceof` would spuriously
455
+ * fail on a structurally-identical error from another realm.
456
+ *
457
+ * @example
458
+ * ```ts
459
+ * try {
460
+ * await db.collection("tickets").insert({ title: "hi" });
461
+ * } catch (err) {
462
+ * if (err instanceof BaerlyError && err.code === "Conflict") {
463
+ * // ... CAS lost; retry
464
+ * }
465
+ * throw err;
466
+ * }
467
+ * ```
468
+ */
469
+ var BaerlyError = class extends Error {
470
+ code;
471
+ cause;
472
+ /**
473
+ * Structured field-path issues, set only when `code === "SchemaError"`.
474
+ * Each entry's `path` is a dotted-key list (e.g. `["assignee", "team"]`
475
+ * or `["items", 3, "qty"]`) that targets the offending field on the
476
+ * input document. `message` is the validator-emitted human string.
477
+ *
478
+ * The HTTP layer's `mapError` renders these into the 400 body via
479
+ * the existing `HttpErrorEnvelope`; older callers that don't know
480
+ * about `issues` see a plain message-only error and stay correct.
481
+ */
482
+ issues;
483
+ /**
484
+ * Raw HTTP status, set only by the client-side wire decoder when
485
+ * inflating an `HttpErrorEnvelope` into this class. Server-side
486
+ * throws never set it (the HTTP layer's `mapError` derives the
487
+ * outbound status from `code`). Useful for diagnostics — e.g. to
488
+ * distinguish 404-as-"no such row" from 404-as-"route not found".
489
+ * Discriminate by `code` for behavior; reach for `status` only when
490
+ * you genuinely need the wire value.
491
+ */
492
+ status;
493
+ constructor(code, message, cause, issues, status) {
494
+ super(message);
495
+ this.name = "BaerlyError";
496
+ this.code = code;
497
+ this.cause = cause;
498
+ if (issues !== void 0) this.issues = issues;
499
+ if (status !== void 0) this.status = status;
500
+ }
501
+ };
502
+ //#endregion
503
+ //#region src/output.ts
504
+ var import_picocolors_browser = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
505
+ var x = String;
506
+ var create = function() {
507
+ return {
508
+ isColorSupported: false,
509
+ reset: x,
510
+ bold: x,
511
+ dim: x,
512
+ italic: x,
513
+ underline: x,
514
+ inverse: x,
515
+ hidden: x,
516
+ strikethrough: x,
517
+ black: x,
518
+ red: x,
519
+ green: x,
520
+ yellow: x,
521
+ blue: x,
522
+ magenta: x,
523
+ cyan: x,
524
+ white: x,
525
+ gray: x,
526
+ bgBlack: x,
527
+ bgRed: x,
528
+ bgGreen: x,
529
+ bgYellow: x,
530
+ bgBlue: x,
531
+ bgMagenta: x,
532
+ bgCyan: x,
533
+ bgWhite: x,
534
+ blackBright: x,
535
+ redBright: x,
536
+ greenBright: x,
537
+ yellowBright: x,
538
+ blueBright: x,
539
+ magentaBright: x,
540
+ cyanBright: x,
541
+ whiteBright: x,
542
+ bgBlackBright: x,
543
+ bgRedBright: x,
544
+ bgGreenBright: x,
545
+ bgYellowBright: x,
546
+ bgBlueBright: x,
547
+ bgMagentaBright: x,
548
+ bgCyanBright: x,
549
+ bgWhiteBright: x
550
+ };
551
+ };
552
+ module.exports = create();
553
+ module.exports.createColors = create;
554
+ })))(), 1);
555
+ let jsonMode = false;
556
+ /** Toggle JSON-envelope output mode. Called from `baerly.ts` and each subcommand. */
557
+ const setJsonMode = (v) => {
558
+ jsonMode = v;
559
+ };
560
+ const isJsonMode = () => jsonMode;
561
+ /**
562
+ * Color helpers — no-ops in JSON mode (so emitted JSON stays
563
+ * machine-parseable) and when `picocolors` detects a non-TTY or
564
+ * `NO_COLOR`.
565
+ */
566
+ const color = {
567
+ red: (s) => jsonMode ? s : import_picocolors_browser.default.red(s),
568
+ yellow: (s) => jsonMode ? s : import_picocolors_browser.default.yellow(s),
569
+ dim: (s) => jsonMode ? s : import_picocolors_browser.default.dim(s)
570
+ };
571
+ /**
572
+ * Emit an error. Text mode preserves the legacy `baerly <cmd>:
573
+ * <code>: <msg>\n` shape that `copy.test.ts` (transitively) and any
574
+ * scripts piping stderr already expect.
575
+ *
576
+ * Two corner cases the brand prefix needs to handle:
577
+ * - When the runBin shim catches a top-level error it passes
578
+ * `command === "baerly"` (or `"create-baerly-storage"`); doubling the
579
+ * brand (`baerly baerly: …`) is ugly. Collapse to just
580
+ * `baerly: <code>: <msg>` in that case.
581
+ * - When `command` is empty (top-level parse errors that haven't
582
+ * matched a subcommand), drop the trailing space and emit
583
+ * `baerly: <code>: <msg>`.
584
+ *
585
+ * JSON-mode envelope is untouched — it carries `command` as a
586
+ * structured field, no double-prefix problem.
587
+ */
588
+ const emitError = (command, code, message) => {
589
+ if (jsonMode) {
590
+ process.stderr.write(`${JSON.stringify({ error: {
591
+ code,
592
+ message,
593
+ command
594
+ } })}\n`);
595
+ return;
596
+ }
597
+ let prefix;
598
+ if (command === "" || command === "baerly") prefix = "baerly";
599
+ else if (command === "create-baerly-storage") prefix = "create-baerly-storage";
600
+ else prefix = `baerly ${command}`;
601
+ process.stderr.write(`${prefix}: ${code}: ${message}\n`);
602
+ };
603
+ /**
604
+ * Emit a success result. No-op in text mode (subcommands stay silent
605
+ * on success, matching the existing contract); in JSON mode writes
606
+ * one structured envelope to stdout.
607
+ */
608
+ const emitSuccess = (data) => {
609
+ if (jsonMode) process.stdout.write(`${JSON.stringify({ result: data })}\n`);
610
+ };
611
+ //#endregion
612
+ //#region src/bin-runner.ts
613
+ /**
614
+ * `runBin` — bin-entry shim around citty 0.2.2's `runCommand`.
615
+ *
616
+ * Why this exists: citty's own `runMain` does not give us enough
617
+ * control over the failure surface. In particular:
618
+ *
619
+ * 1. citty 0.2.2's `runCommand` does NOT intercept `--help` or
620
+ * `--version` on a parent command that has `subCommands`. A bare
621
+ * `baerly --help` invocation tries to *dispatch* (and fails on
622
+ * "no subcommand").
623
+ * 2. `runMain` translates the internal `CLIError` (the one thrown
624
+ * for unknown flags, invalid enum values, missing required
625
+ * flags) into a bare `process.stderr.write` + `process.exit(1)`.
626
+ * We want every error path to flow through {@link emitError}
627
+ * so `--json` envelopes work even on parse-time failures, and
628
+ * the brand-prefix collapse for top-level errors stays
629
+ * consistent.
630
+ *
631
+ * Behavior:
632
+ * - Sets `setJsonMode(argv.includes("--json"))` as the first
633
+ * action so parse-time errors still emit a JSON envelope.
634
+ * - Walks `cmd.subCommands` to handle `--help` / `-h` and
635
+ * `--version` / `-v` at any nesting depth.
636
+ * - Translates citty `CLIError`s into `BaerlyError("InvalidConfig",
637
+ * …)` semantics.
638
+ * - Maps `BaerlyError.code` through the same 3-bucket exit-code
639
+ * table the per-subcommand wrappers use (`InvalidConfig → 1`,
640
+ * `Conflict|Internal|InvalidResponse → 3`, else 2).
641
+ */
642
+ const errorToExitCode = (code) => {
643
+ if (code === "InvalidConfig") return 1;
644
+ if (code === "Conflict" || code === "Internal" || code === "InvalidResponse") return 3;
645
+ return 2;
646
+ };
647
+ const resolve = async (v) => {
648
+ if (typeof v === "function") return v();
649
+ return v;
650
+ };
651
+ /**
652
+ * Walk `cmd.subCommands` along the leading positional args to find
653
+ * the deepest matched subcommand. Returns `cmd` itself when no
654
+ * positional matches, so `<bin> --help` (no subcommand) still
655
+ * resolves to the top-level command.
656
+ */
657
+ const resolveTarget = async (cmd, positional) => {
658
+ let cur = cmd;
659
+ for (const arg of positional) {
660
+ const subs = cur.subCommands;
661
+ if (subs === void 0) break;
662
+ const next = (await resolve(subs))[arg];
663
+ if (next === void 0) break;
664
+ cur = await resolve(next);
665
+ }
666
+ return cur;
667
+ };
668
+ /** Return the leading positional args (everything before the first `--flag`). */
669
+ const leadingPositionals = (argv) => {
670
+ const out = [];
671
+ for (const a of argv) {
672
+ if (a.startsWith("-")) break;
673
+ out.push(a);
674
+ }
675
+ return out;
676
+ };
677
+ /**
678
+ * Bin-entry runner. Returns a promise that never resolves on
679
+ * success (it calls `process.exit(0)`); on error it `process.exit`s
680
+ * with the mapped code.
681
+ *
682
+ * `brand` controls the {@link emitError} prefix on top-level
683
+ * failures — `"baerly"` for the main CLI, `"create-baerly-storage"` for
684
+ * the scaffolder.
685
+ */
686
+ const runBin = async (cmd, argv, brand = "baerly") => {
687
+ setJsonMode(argv.includes("--json"));
688
+ if (argv.includes("--help") || argv.includes("-h")) {
689
+ await showUsage(await resolveTarget(cmd, leadingPositionals(argv)));
690
+ process.exit(0);
691
+ }
692
+ if (argv.includes("--version") || argv.includes("-v")) {
693
+ const version = (await resolve(cmd.meta) ?? {}).version;
694
+ if (typeof version !== "string" || version.length === 0) {
695
+ emitError(brand, "InvalidConfig", "no version declared on this command");
696
+ process.exit(1);
697
+ }
698
+ process.stdout.write(`${version}\n`);
699
+ process.exit(0);
700
+ }
701
+ try {
702
+ await runCommand(cmd, { rawArgs: [...argv] });
703
+ process.exit(0);
704
+ } catch (error) {
705
+ if (error instanceof BaerlyError) {
706
+ emitError(brand, error.code, error.message);
707
+ process.exit(errorToExitCode(error.code));
708
+ }
709
+ emitError(brand, "InvalidConfig", error instanceof Error ? error.message : String(error));
710
+ process.exit(1);
711
+ }
712
+ };
713
+ //#endregion
714
+ //#region src/baerly.ts
715
+ /**
716
+ * `baerly` — vendorless document database CLI. Entry point bundled
717
+ * to `dist/baerly.js` by `rolldown.config.ts` with a `#!/usr/bin/env
718
+ * node` banner.
719
+ *
720
+ * Subcommands live in their own modules and register via citty's
721
+ * `defineCommand`. Adding a new subcommand: write its module, export
722
+ * a `defineCommand` block, drop it into `subCommands` below as a
723
+ * lazy `() => import("./x.ts").then(m => m.x)` factory. citty 0.2.2
724
+ * supports `Resolvable<CommandDef>` in `subCommands`, so the factory
725
+ * shape is type-correct and only the dispatched module's transitive
726
+ * imports are evaluated at startup.
727
+ *
728
+ * Exit codes are documented in `packages/cli/README.md` and per-
729
+ * subcommand in each module's docstring.
730
+ */
731
+ runBin(defineCommand({
732
+ meta: {
733
+ name: "baerly",
734
+ version: "0.0.0",
735
+ description: "Vendorless document database CLI."
736
+ },
737
+ subCommands: {
738
+ deploy: () => import("./deploy-BB-wqbhf.js").then((m) => m.deploy),
739
+ doctor: () => import("./doctor-B8h9GCN9.js").then((m) => m.doctor),
740
+ inspect: () => import("./inspect-x02aFWnh.js").then((m) => m.inspect),
741
+ export: () => import("./export-Dz2PZKSR.js").then((m) => m.exportCmd),
742
+ cost: () => import("./cost-B1WiZxlf.js").then((m) => m.cost),
743
+ admin: defineCommand({
744
+ meta: {
745
+ name: "admin",
746
+ description: "Operator commands — reconciliation and inspection."
747
+ },
748
+ subCommands: {
749
+ "rebuild-index": () => import("./rebuild-index-DwXM0WfA.js").then((m) => m.rebuildIndexCmd),
750
+ dump: () => import("./dump-BHo_sIMZ.js").then((m) => m.dumpCmd),
751
+ restore: () => import("./restore-CbKVMMpm.js").then((m) => m.restoreCmd),
752
+ fsck: () => import("./fsck-DEz9lyCy.js").then((m) => m.fsckCmd),
753
+ usage: () => import("./usage-RVUQMLop.js").then((m) => m.usageCmd)
754
+ }
755
+ })
756
+ }
757
+ }), process.argv.slice(2), "baerly");
758
+ //#endregion
759
+ export { setJsonMode as a, parseArgs$1 as c, isJsonMode as i, emitError as n, BaerlyError as o, emitSuccess as r, defineCommand as s, color as t };
760
+
761
+ //# sourceMappingURL=baerly.js.map