@tinycloud/cli 1.5.0-beta.1 → 1.5.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37447,9 +37447,12 @@ function registerKvCommand(program) {
37447
37447
  return handleError(error);
37448
37448
  }
37449
37449
  });
37450
- kv.command("put <key> [value]").description("Set a value").option("--file <path>", "Read value from file").option("--stdin", "Read value from stdin").option("--space <name|uri>", "Target a non-primary space (short name or full URI)").action(async (key, value, options, cmd) => {
37450
+ kv.command("put <key> [value]").description("Set a value").option("--file <path>", "Read value from file").option("--stdin", "Read value from stdin").option("--if-none-match <value>", "`--if-none-match '*'`: Write only if the key doesn't exist yet; never overwrite").option("--space <name|uri>", "Target a non-primary space (short name or full URI)").action(async (key, value, options, cmd) => {
37451
37451
  try {
37452
37452
  assertAddressableKey(key);
37453
+ if (options.ifNoneMatch !== void 0 && options.ifNoneMatch !== "*") {
37454
+ throw new CLIError("USAGE_ERROR", "`--if-none-match` only accepts `'*'`.", ExitCode.USAGE_ERROR);
37455
+ }
37453
37456
  const globalOpts = cmd.optsWithGlobals();
37454
37457
  const ctx = await ProfileManager.resolveContext(globalOpts);
37455
37458
  const node = await ensureAuthenticated(ctx);
@@ -37473,8 +37476,15 @@ function registerKvCommand(program) {
37473
37476
  }
37474
37477
  }
37475
37478
  const { kv: kv2, spaceUri } = await kvHandle(node, options.space, ctx.profile);
37476
- const result = await withSpinner(`Writing ${key}...`, () => kv2.put(key, putValue));
37479
+ const result = await withSpinner(`Writing ${key}...`, () => kv2.put(
37480
+ key,
37481
+ putValue,
37482
+ options.ifNoneMatch === "*" ? { ifNoneMatch: "*" } : void 0
37483
+ ));
37477
37484
  if (!result.ok) {
37485
+ if (options.ifNoneMatch === "*" && result.error.code === "KV_PRECONDITION_FAILED") {
37486
+ throw new CLIError("KV_ALREADY_EXISTS", `Key "${key}" already exists, so nothing was written.`, ExitCode.PERMISSION_DENIED);
37487
+ }
37478
37488
  await throwKvError(result.error, spaceUri, ctx.profile);
37479
37489
  }
37480
37490
  outputJson({ key, written: true, ...retryFields(result.data?.retry) });