@karakeep/cli 0.23.0 → 0.25.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 (2) hide show
  1. package/dist/index.mjs +805 -278
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,14 +1,13 @@
1
1
  #! /usr/bin/env node
2
2
  var _a, _b, _c, _d, _e, _f;
3
- import * as fs$1 from "node:fs";
3
+ import * as require$$3 from "node:fs";
4
+ import require$$3__default from "node:fs";
4
5
  import process$2 from "node:process";
5
6
  import os from "node:os";
6
7
  import tty from "node:tty";
7
- import require$$0 from "events";
8
- import require$$1 from "child_process";
9
- import require$$2 from "path";
10
- import require$$3 from "fs";
11
- import require$$4 from "process";
8
+ import require$$0 from "node:events";
9
+ import require$$1 from "node:child_process";
10
+ import require$$2 from "node:path";
12
11
  let globalOpts = void 0;
13
12
  function setGlobalOptions(opts) {
14
13
  globalOpts = opts;
@@ -272,10 +271,10 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
272
271
  return 1;
273
272
  }
274
273
  if ("CI" in env) {
275
- if ("GITHUB_ACTIONS" in env || "GITEA_ACTIONS" in env) {
274
+ if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
276
275
  return 3;
277
276
  }
278
- if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
277
+ if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
279
278
  return 1;
280
279
  }
281
280
  return min;
@@ -2355,7 +2354,6 @@ let CommanderError$3 = class CommanderError extends Error {
2355
2354
  * @param {number} exitCode suggested exit code which could be used with process.exit
2356
2355
  * @param {string} code an id string representing the error
2357
2356
  * @param {string} message human-readable description of the error
2358
- * @constructor
2359
2357
  */
2360
2358
  constructor(exitCode, code, message) {
2361
2359
  super(message);
@@ -2370,7 +2368,6 @@ let InvalidArgumentError$4 = class InvalidArgumentError extends CommanderError$3
2370
2368
  /**
2371
2369
  * Constructs the InvalidArgumentError class
2372
2370
  * @param {string} [message] explanation of why argument is invalid
2373
- * @constructor
2374
2371
  */
2375
2372
  constructor(message) {
2376
2373
  super(1, "commander.invalidArgument", message);
@@ -2425,7 +2422,7 @@ let Argument$3 = class Argument {
2425
2422
  return this._name;
2426
2423
  }
2427
2424
  /**
2428
- * @package internal use only
2425
+ * @package
2429
2426
  */
2430
2427
  _concatValue(value, previous) {
2431
2428
  if (previous === this.defaultValue || !Array.isArray(previous)) {
@@ -2465,7 +2462,9 @@ let Argument$3 = class Argument {
2465
2462
  this.argChoices = values.slice();
2466
2463
  this.parseArg = (arg, previous) => {
2467
2464
  if (!this.argChoices.includes(arg)) {
2468
- throw new InvalidArgumentError$3(`Allowed choices are ${this.argChoices.join(", ")}.`);
2465
+ throw new InvalidArgumentError$3(
2466
+ `Allowed choices are ${this.argChoices.join(", ")}.`
2467
+ );
2469
2468
  }
2470
2469
  if (this.variadic) {
2471
2470
  return this._concatValue(arg, previous);
@@ -2476,6 +2475,8 @@ let Argument$3 = class Argument {
2476
2475
  }
2477
2476
  /**
2478
2477
  * Make argument required.
2478
+ *
2479
+ * @returns {Argument}
2479
2480
  */
2480
2481
  argRequired() {
2481
2482
  this.required = true;
@@ -2483,6 +2484,8 @@ let Argument$3 = class Argument {
2483
2484
  }
2484
2485
  /**
2485
2486
  * Make argument optional.
2487
+ *
2488
+ * @returns {Argument}
2486
2489
  */
2487
2490
  argOptional() {
2488
2491
  this.required = false;
@@ -2529,7 +2532,7 @@ let Help$3 = class Help {
2529
2532
  *
2530
2533
  * @param {Option} a
2531
2534
  * @param {Option} b
2532
- * @returns number
2535
+ * @returns {number}
2533
2536
  */
2534
2537
  compareOptions(a, b) {
2535
2538
  const getSortKey = (option2) => {
@@ -2552,9 +2555,13 @@ let Help$3 = class Help {
2552
2555
  if (!removeShort && !removeLong) {
2553
2556
  visibleOptions.push(helpOption);
2554
2557
  } else if (helpOption.long && !removeLong) {
2555
- visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
2558
+ visibleOptions.push(
2559
+ cmd.createOption(helpOption.long, helpOption.description)
2560
+ );
2556
2561
  } else if (helpOption.short && !removeShort) {
2557
- visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
2562
+ visibleOptions.push(
2563
+ cmd.createOption(helpOption.short, helpOption.description)
2564
+ );
2558
2565
  }
2559
2566
  }
2560
2567
  if (this.sortOptions) {
@@ -2573,7 +2580,9 @@ let Help$3 = class Help {
2573
2580
  return [];
2574
2581
  const globalOptions = [];
2575
2582
  for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
2576
- const visibleOptions = ancestorCmd.options.filter((option2) => !option2.hidden);
2583
+ const visibleOptions = ancestorCmd.options.filter(
2584
+ (option2) => !option2.hidden
2585
+ );
2577
2586
  globalOptions.push(...visibleOptions);
2578
2587
  }
2579
2588
  if (this.sortOptions) {
@@ -2728,7 +2737,9 @@ let Help$3 = class Help {
2728
2737
  if (option2.defaultValue !== void 0) {
2729
2738
  const showDefault = option2.required || option2.optional || option2.isBoolean() && typeof option2.defaultValue === "boolean";
2730
2739
  if (showDefault) {
2731
- extraInfo.push(`default: ${option2.defaultValueDescription || JSON.stringify(option2.defaultValue)}`);
2740
+ extraInfo.push(
2741
+ `default: ${option2.defaultValueDescription || JSON.stringify(option2.defaultValue)}`
2742
+ );
2732
2743
  }
2733
2744
  }
2734
2745
  if (option2.presetArg !== void 0 && option2.optional) {
@@ -2757,7 +2768,9 @@ let Help$3 = class Help {
2757
2768
  );
2758
2769
  }
2759
2770
  if (argument2.defaultValue !== void 0) {
2760
- extraInfo.push(`default: ${argument2.defaultValueDescription || JSON.stringify(argument2.defaultValue)}`);
2771
+ extraInfo.push(
2772
+ `default: ${argument2.defaultValueDescription || JSON.stringify(argument2.defaultValue)}`
2773
+ );
2761
2774
  }
2762
2775
  if (extraInfo.length > 0) {
2763
2776
  const extraDescripton = `(${extraInfo.join(", ")})`;
@@ -2783,7 +2796,11 @@ let Help$3 = class Help {
2783
2796
  function formatItem(term, description) {
2784
2797
  if (description) {
2785
2798
  const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
2786
- return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
2799
+ return helper.wrap(
2800
+ fullText,
2801
+ helpWidth - itemIndentWidth,
2802
+ termWidth + itemSeparatorWidth
2803
+ );
2787
2804
  }
2788
2805
  return term;
2789
2806
  }
@@ -2793,30 +2810,49 @@ let Help$3 = class Help {
2793
2810
  let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
2794
2811
  const commandDescription = helper.commandDescription(cmd);
2795
2812
  if (commandDescription.length > 0) {
2796
- output = output.concat([helper.wrap(commandDescription, helpWidth, 0), ""]);
2813
+ output = output.concat([
2814
+ helper.wrap(commandDescription, helpWidth, 0),
2815
+ ""
2816
+ ]);
2797
2817
  }
2798
2818
  const argumentList = helper.visibleArguments(cmd).map((argument2) => {
2799
- return formatItem(helper.argumentTerm(argument2), helper.argumentDescription(argument2));
2819
+ return formatItem(
2820
+ helper.argumentTerm(argument2),
2821
+ helper.argumentDescription(argument2)
2822
+ );
2800
2823
  });
2801
2824
  if (argumentList.length > 0) {
2802
2825
  output = output.concat(["Arguments:", formatList(argumentList), ""]);
2803
2826
  }
2804
2827
  const optionList = helper.visibleOptions(cmd).map((option2) => {
2805
- return formatItem(helper.optionTerm(option2), helper.optionDescription(option2));
2828
+ return formatItem(
2829
+ helper.optionTerm(option2),
2830
+ helper.optionDescription(option2)
2831
+ );
2806
2832
  });
2807
2833
  if (optionList.length > 0) {
2808
2834
  output = output.concat(["Options:", formatList(optionList), ""]);
2809
2835
  }
2810
2836
  if (this.showGlobalOptions) {
2811
2837
  const globalOptionList = helper.visibleGlobalOptions(cmd).map((option2) => {
2812
- return formatItem(helper.optionTerm(option2), helper.optionDescription(option2));
2838
+ return formatItem(
2839
+ helper.optionTerm(option2),
2840
+ helper.optionDescription(option2)
2841
+ );
2813
2842
  });
2814
2843
  if (globalOptionList.length > 0) {
2815
- output = output.concat(["Global Options:", formatList(globalOptionList), ""]);
2844
+ output = output.concat([
2845
+ "Global Options:",
2846
+ formatList(globalOptionList),
2847
+ ""
2848
+ ]);
2816
2849
  }
2817
2850
  }
2818
2851
  const commandList = helper.visibleCommands(cmd).map((cmd2) => {
2819
- return formatItem(helper.subcommandTerm(cmd2), helper.subcommandDescription(cmd2));
2852
+ return formatItem(
2853
+ helper.subcommandTerm(cmd2),
2854
+ helper.subcommandDescription(cmd2)
2855
+ );
2820
2856
  });
2821
2857
  if (commandList.length > 0) {
2822
2858
  output = output.concat(["Commands:", formatList(commandList), ""]);
@@ -2862,8 +2898,11 @@ let Help$3 = class Help {
2862
2898
  const indentString = " ".repeat(indent);
2863
2899
  const zeroWidthSpace = "​";
2864
2900
  const breaks = `\\s${zeroWidthSpace}`;
2865
- const regex2 = new RegExp(`
2866
- |.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`, "g");
2901
+ const regex2 = new RegExp(
2902
+ `
2903
+ |.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`,
2904
+ "g"
2905
+ );
2867
2906
  const lines = columnText.match(regex2) || [];
2868
2907
  return leadingStr + lines.map((line, i) => {
2869
2908
  if (line === "\n")
@@ -2958,7 +2997,7 @@ let Option$3 = class Option {
2958
2997
  * .addOption(new Option('--log', 'write logging information to file'))
2959
2998
  * .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
2960
2999
  *
2961
- * @param {Object} impliedOptionValues
3000
+ * @param {object} impliedOptionValues
2962
3001
  * @return {Option}
2963
3002
  */
2964
3003
  implies(impliedOptionValues) {
@@ -3013,7 +3052,7 @@ let Option$3 = class Option {
3013
3052
  return this;
3014
3053
  }
3015
3054
  /**
3016
- * @package internal use only
3055
+ * @package
3017
3056
  */
3018
3057
  _concatValue(value, previous) {
3019
3058
  if (previous === this.defaultValue || !Array.isArray(previous)) {
@@ -3031,7 +3070,9 @@ let Option$3 = class Option {
3031
3070
  this.argChoices = values.slice();
3032
3071
  this.parseArg = (arg, previous) => {
3033
3072
  if (!this.argChoices.includes(arg)) {
3034
- throw new InvalidArgumentError$2(`Allowed choices are ${this.argChoices.join(", ")}.`);
3073
+ throw new InvalidArgumentError$2(
3074
+ `Allowed choices are ${this.argChoices.join(", ")}.`
3075
+ );
3035
3076
  }
3036
3077
  if (this.variadic) {
3037
3078
  return this._concatValue(arg, previous);
@@ -3065,7 +3106,7 @@ let Option$3 = class Option {
3065
3106
  *
3066
3107
  * @param {string} arg
3067
3108
  * @return {boolean}
3068
- * @package internal use only
3109
+ * @package
3069
3110
  */
3070
3111
  is(arg) {
3071
3112
  return this.short === arg || this.long === arg;
@@ -3076,7 +3117,7 @@ let Option$3 = class Option {
3076
3117
  * Options are one of boolean, negated, required argument, or optional argument.
3077
3118
  *
3078
3119
  * @return {boolean}
3079
- * @package internal use only
3120
+ * @package
3080
3121
  */
3081
3122
  isBoolean() {
3082
3123
  return !this.required && !this.optional && !this.negate;
@@ -3219,8 +3260,8 @@ suggestSimilar$2.suggestSimilar = suggestSimilar$1;
3219
3260
  const EventEmitter = require$$0.EventEmitter;
3220
3261
  const childProcess = require$$1;
3221
3262
  const path = require$$2;
3222
- const fs = require$$3;
3223
- const process$1 = require$$4;
3263
+ const fs = require$$3__default;
3264
+ const process$1 = process$2;
3224
3265
  const { Argument: Argument$2, humanReadableArgName } = argument;
3225
3266
  const { CommanderError: CommanderError$2 } = error;
3226
3267
  const { Help: Help$2 } = help;
@@ -3331,8 +3372,8 @@ let Command$2 = class Command extends EventEmitter {
3331
3372
  * .command('stop [service]', 'stop named service, or all if no name supplied');
3332
3373
  *
3333
3374
  * @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
3334
- * @param {(Object|string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
3335
- * @param {Object} [execOpts] - configuration options (for executable)
3375
+ * @param {(object | string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
3376
+ * @param {object} [execOpts] - configuration options (for executable)
3336
3377
  * @return {Command} returns new command for action handler, or `this` for executable command
3337
3378
  */
3338
3379
  command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
@@ -3387,8 +3428,8 @@ let Command$2 = class Command extends EventEmitter {
3387
3428
  * You can customise the help by overriding Help properties using configureHelp(),
3388
3429
  * or with a subclass of Help by overriding createHelp().
3389
3430
  *
3390
- * @param {Object} [configuration] - configuration options
3391
- * @return {(Command|Object)} `this` command for chaining, or stored configuration
3431
+ * @param {object} [configuration] - configuration options
3432
+ * @return {(Command | object)} `this` command for chaining, or stored configuration
3392
3433
  */
3393
3434
  configureHelp(configuration) {
3394
3435
  if (configuration === void 0)
@@ -3411,8 +3452,8 @@ let Command$2 = class Command extends EventEmitter {
3411
3452
  * // functions based on what is being written out
3412
3453
  * outputError(str, write) // used for displaying errors, and not used for displaying help
3413
3454
  *
3414
- * @param {Object} [configuration] - configuration options
3415
- * @return {(Command|Object)} `this` command for chaining, or stored configuration
3455
+ * @param {object} [configuration] - configuration options
3456
+ * @return {(Command | object)} `this` command for chaining, or stored configuration
3416
3457
  */
3417
3458
  configureOutput(configuration) {
3418
3459
  if (configuration === void 0)
@@ -3448,7 +3489,7 @@ let Command$2 = class Command extends EventEmitter {
3448
3489
  * See .command() for creating an attached subcommand which inherits settings from its parent.
3449
3490
  *
3450
3491
  * @param {Command} cmd - new subcommand
3451
- * @param {Object} [opts] - configuration options
3492
+ * @param {object} [opts] - configuration options
3452
3493
  * @return {Command} `this` command for chaining
3453
3494
  */
3454
3495
  addCommand(cmd, opts) {
@@ -3531,10 +3572,14 @@ let Command$2 = class Command extends EventEmitter {
3531
3572
  addArgument(argument2) {
3532
3573
  const previousArgument = this.registeredArguments.slice(-1)[0];
3533
3574
  if (previousArgument && previousArgument.variadic) {
3534
- throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
3575
+ throw new Error(
3576
+ `only the last argument can be variadic '${previousArgument.name()}'`
3577
+ );
3535
3578
  }
3536
3579
  if (argument2.required && argument2.defaultValue !== void 0 && argument2.parseArg === void 0) {
3537
- throw new Error(`a default value for a required argument is never used: '${argument2.name()}'`);
3580
+ throw new Error(
3581
+ `a default value for a required argument is never used: '${argument2.name()}'`
3582
+ );
3538
3583
  }
3539
3584
  this.registeredArguments.push(argument2);
3540
3585
  return this;
@@ -3542,6 +3587,7 @@ let Command$2 = class Command extends EventEmitter {
3542
3587
  /**
3543
3588
  * Customise or override default help command. By default a help command is automatically added if your command has subcommands.
3544
3589
  *
3590
+ * @example
3545
3591
  * program.helpCommand('help [cmd]');
3546
3592
  * program.helpCommand('help [cmd]', 'show help');
3547
3593
  * program.helpCommand(false); // suppress default help command
@@ -3721,7 +3767,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
3721
3767
  * Register option if no conflicts found, or throw on conflict.
3722
3768
  *
3723
3769
  * @param {Option} option
3724
- * @api private
3770
+ * @private
3725
3771
  */
3726
3772
  _registerOption(option2) {
3727
3773
  const matchingOption = option2.short && this._findOption(option2.short) || option2.long && this._findOption(option2.long);
@@ -3737,17 +3783,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
3737
3783
  * Register command if no conflicts found, or throw on conflict.
3738
3784
  *
3739
3785
  * @param {Command} command
3740
- * @api private
3786
+ * @private
3741
3787
  */
3742
3788
  _registerCommand(command2) {
3743
3789
  const knownBy = (cmd) => {
3744
3790
  return [cmd.name()].concat(cmd.aliases());
3745
3791
  };
3746
- const alreadyUsed = knownBy(command2).find((name) => this._findCommand(name));
3792
+ const alreadyUsed = knownBy(command2).find(
3793
+ (name) => this._findCommand(name)
3794
+ );
3747
3795
  if (alreadyUsed) {
3748
3796
  const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
3749
3797
  const newCmd = knownBy(command2).join("|");
3750
- throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
3798
+ throw new Error(
3799
+ `cannot add command '${newCmd}' as already have command '${existingCmd}'`
3800
+ );
3751
3801
  }
3752
3802
  this.commands.push(command2);
3753
3803
  }
@@ -3764,7 +3814,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
3764
3814
  if (option2.negate) {
3765
3815
  const positiveLongFlag = option2.long.replace(/^--no-/, "--");
3766
3816
  if (!this._findOption(positiveLongFlag)) {
3767
- this.setOptionValueWithSource(name, option2.defaultValue === void 0 ? true : option2.defaultValue, "default");
3817
+ this.setOptionValueWithSource(
3818
+ name,
3819
+ option2.defaultValue === void 0 ? true : option2.defaultValue,
3820
+ "default"
3821
+ );
3768
3822
  }
3769
3823
  } else if (option2.defaultValue !== void 0) {
3770
3824
  this.setOptionValueWithSource(name, option2.defaultValue, "default");
@@ -3805,11 +3859,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
3805
3859
  /**
3806
3860
  * Internal implementation shared by .option() and .requiredOption()
3807
3861
  *
3862
+ * @return {Command} `this` command for chaining
3808
3863
  * @private
3809
3864
  */
3810
3865
  _optionEx(config, flags, description, fn, defaultValue) {
3811
3866
  if (typeof flags === "object" && flags instanceof Option$2) {
3812
- throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
3867
+ throw new Error(
3868
+ "To add an Option object use addOption() instead of option() or requiredOption()"
3869
+ );
3813
3870
  }
3814
3871
  const option2 = this.createOption(flags, description);
3815
3872
  option2.makeOptionMandatory(!!config.mandatory);
@@ -3852,19 +3909,25 @@ Expecting one of '${allowedValues.join("', '")}'`);
3852
3909
  return this._optionEx({}, flags, description, parseArg, defaultValue);
3853
3910
  }
3854
3911
  /**
3855
- * Add a required option which must have a value after parsing. This usually means
3856
- * the option must be specified on the command line. (Otherwise the same as .option().)
3857
- *
3858
- * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
3859
- *
3860
- * @param {string} flags
3861
- * @param {string} [description]
3862
- * @param {(Function|*)} [parseArg] - custom option processing function or default value
3863
- * @param {*} [defaultValue]
3864
- * @return {Command} `this` command for chaining
3865
- */
3912
+ * Add a required option which must have a value after parsing. This usually means
3913
+ * the option must be specified on the command line. (Otherwise the same as .option().)
3914
+ *
3915
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
3916
+ *
3917
+ * @param {string} flags
3918
+ * @param {string} [description]
3919
+ * @param {(Function|*)} [parseArg] - custom option processing function or default value
3920
+ * @param {*} [defaultValue]
3921
+ * @return {Command} `this` command for chaining
3922
+ */
3866
3923
  requiredOption(flags, description, parseArg, defaultValue) {
3867
- return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
3924
+ return this._optionEx(
3925
+ { mandatory: true },
3926
+ flags,
3927
+ description,
3928
+ parseArg,
3929
+ defaultValue
3930
+ );
3868
3931
  }
3869
3932
  /**
3870
3933
  * Alter parsing of short flags with optional values.
@@ -3874,7 +3937,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
3874
3937
  * program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
3875
3938
  * program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
3876
3939
  *
3877
- * @param {boolean} [combine=true] - if `true` or omitted, an optional value can be specified directly after the flag.
3940
+ * @param {boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.
3941
+ * @return {Command} `this` command for chaining
3878
3942
  */
3879
3943
  combineFlagAndOptionalValue(combine = true) {
3880
3944
  this._combineFlagAndOptionalValue = !!combine;
@@ -3883,8 +3947,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
3883
3947
  /**
3884
3948
  * Allow unknown options on the command line.
3885
3949
  *
3886
- * @param {boolean} [allowUnknown=true] - if `true` or omitted, no error will be thrown
3887
- * for unknown options.
3950
+ * @param {boolean} [allowUnknown] - if `true` or omitted, no error will be thrown for unknown options.
3951
+ * @return {Command} `this` command for chaining
3888
3952
  */
3889
3953
  allowUnknownOption(allowUnknown = true) {
3890
3954
  this._allowUnknownOption = !!allowUnknown;
@@ -3893,8 +3957,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
3893
3957
  /**
3894
3958
  * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
3895
3959
  *
3896
- * @param {boolean} [allowExcess=true] - if `true` or omitted, no error will be thrown
3897
- * for excess arguments.
3960
+ * @param {boolean} [allowExcess] - if `true` or omitted, no error will be thrown for excess arguments.
3961
+ * @return {Command} `this` command for chaining
3898
3962
  */
3899
3963
  allowExcessArguments(allowExcess = true) {
3900
3964
  this._allowExcessArguments = !!allowExcess;
@@ -3905,7 +3969,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
3905
3969
  * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
3906
3970
  * The default behaviour is non-positional and global options may appear anywhere on the command line.
3907
3971
  *
3908
- * @param {boolean} [positional=true]
3972
+ * @param {boolean} [positional]
3973
+ * @return {Command} `this` command for chaining
3909
3974
  */
3910
3975
  enablePositionalOptions(positional = true) {
3911
3976
  this._enablePositionalOptions = !!positional;
@@ -3917,8 +3982,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
3917
3982
  * positional options to have been enabled on the program (parent commands).
3918
3983
  * The default behaviour is non-positional and options may appear before or after command-arguments.
3919
3984
  *
3920
- * @param {boolean} [passThrough=true]
3921
- * for unknown options.
3985
+ * @param {boolean} [passThrough] for unknown options.
3986
+ * @return {Command} `this` command for chaining
3922
3987
  */
3923
3988
  passThroughOptions(passThrough = true) {
3924
3989
  this._passThroughOptions = !!passThrough;
@@ -3930,22 +3995,26 @@ Expecting one of '${allowedValues.join("', '")}'`);
3930
3995
  */
3931
3996
  _checkForBrokenPassThrough() {
3932
3997
  if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
3933
- throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
3998
+ throw new Error(
3999
+ `passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`
4000
+ );
3934
4001
  }
3935
4002
  }
3936
4003
  /**
3937
- * Whether to store option values as properties on command object,
3938
- * or store separately (specify false). In both cases the option values can be accessed using .opts().
3939
- *
3940
- * @param {boolean} [storeAsProperties=true]
3941
- * @return {Command} `this` command for chaining
3942
- */
4004
+ * Whether to store option values as properties on command object,
4005
+ * or store separately (specify false). In both cases the option values can be accessed using .opts().
4006
+ *
4007
+ * @param {boolean} [storeAsProperties=true]
4008
+ * @return {Command} `this` command for chaining
4009
+ */
3943
4010
  storeOptionsAsProperties(storeAsProperties = true) {
3944
4011
  if (this.options.length) {
3945
4012
  throw new Error("call .storeOptionsAsProperties() before adding options");
3946
4013
  }
3947
4014
  if (Object.keys(this._optionValues).length) {
3948
- throw new Error("call .storeOptionsAsProperties() before setting option values");
4015
+ throw new Error(
4016
+ "call .storeOptionsAsProperties() before setting option values"
4017
+ );
3949
4018
  }
3950
4019
  this._storeOptionsAsProperties = !!storeAsProperties;
3951
4020
  return this;
@@ -3954,7 +4023,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
3954
4023
  * Retrieve option value.
3955
4024
  *
3956
4025
  * @param {string} key
3957
- * @return {Object} value
4026
+ * @return {object} value
3958
4027
  */
3959
4028
  getOptionValue(key) {
3960
4029
  if (this._storeOptionsAsProperties) {
@@ -3966,20 +4035,20 @@ Expecting one of '${allowedValues.join("', '")}'`);
3966
4035
  * Store option value.
3967
4036
  *
3968
4037
  * @param {string} key
3969
- * @param {Object} value
4038
+ * @param {object} value
3970
4039
  * @return {Command} `this` command for chaining
3971
4040
  */
3972
4041
  setOptionValue(key, value) {
3973
4042
  return this.setOptionValueWithSource(key, value, void 0);
3974
4043
  }
3975
4044
  /**
3976
- * Store option value and where the value came from.
3977
- *
3978
- * @param {string} key
3979
- * @param {Object} value
3980
- * @param {string} source - expected values are default/config/env/cli/implied
3981
- * @return {Command} `this` command for chaining
3982
- */
4045
+ * Store option value and where the value came from.
4046
+ *
4047
+ * @param {string} key
4048
+ * @param {object} value
4049
+ * @param {string} source - expected values are default/config/env/cli/implied
4050
+ * @return {Command} `this` command for chaining
4051
+ */
3983
4052
  setOptionValueWithSource(key, value, source) {
3984
4053
  if (this._storeOptionsAsProperties) {
3985
4054
  this[key] = value;
@@ -3990,22 +4059,22 @@ Expecting one of '${allowedValues.join("', '")}'`);
3990
4059
  return this;
3991
4060
  }
3992
4061
  /**
3993
- * Get source of option value.
3994
- * Expected values are default | config | env | cli | implied
3995
- *
3996
- * @param {string} key
3997
- * @return {string}
3998
- */
4062
+ * Get source of option value.
4063
+ * Expected values are default | config | env | cli | implied
4064
+ *
4065
+ * @param {string} key
4066
+ * @return {string}
4067
+ */
3999
4068
  getOptionValueSource(key) {
4000
4069
  return this._optionValueSources[key];
4001
4070
  }
4002
4071
  /**
4003
- * Get source of option value. See also .optsWithGlobals().
4004
- * Expected values are default | config | env | cli | implied
4005
- *
4006
- * @param {string} key
4007
- * @return {string}
4008
- */
4072
+ * Get source of option value. See also .optsWithGlobals().
4073
+ * Expected values are default | config | env | cli | implied
4074
+ *
4075
+ * @param {string} key
4076
+ * @return {string}
4077
+ */
4009
4078
  getOptionValueSourceWithGlobals(key) {
4010
4079
  let source;
4011
4080
  this._getCommandAndAncestors().forEach((cmd) => {
@@ -4022,15 +4091,22 @@ Expecting one of '${allowedValues.join("', '")}'`);
4022
4091
  * @private
4023
4092
  */
4024
4093
  _prepareUserArgs(argv, parseOptions) {
4094
+ var _a2;
4025
4095
  if (argv !== void 0 && !Array.isArray(argv)) {
4026
4096
  throw new Error("first parameter to parse must be array or undefined");
4027
4097
  }
4028
4098
  parseOptions = parseOptions || {};
4029
- if (argv === void 0) {
4030
- argv = process$1.argv;
4031
- if (process$1.versions && process$1.versions.electron) {
4099
+ if (argv === void 0 && parseOptions.from === void 0) {
4100
+ if ((_a2 = process$1.versions) == null ? void 0 : _a2.electron) {
4032
4101
  parseOptions.from = "electron";
4033
4102
  }
4103
+ const execArgv = process$1.execArgv ?? [];
4104
+ if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
4105
+ parseOptions.from = "eval";
4106
+ }
4107
+ }
4108
+ if (argv === void 0) {
4109
+ argv = process$1.argv;
4034
4110
  }
4035
4111
  this.rawArgs = argv.slice();
4036
4112
  let userArgs;
@@ -4051,8 +4127,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
4051
4127
  case "user":
4052
4128
  userArgs = argv.slice(0);
4053
4129
  break;
4130
+ case "eval":
4131
+ userArgs = argv.slice(1);
4132
+ break;
4054
4133
  default:
4055
- throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
4134
+ throw new Error(
4135
+ `unexpected parse option { from: '${parseOptions.from}' }`
4136
+ );
4056
4137
  }
4057
4138
  if (!this._name && this._scriptPath)
4058
4139
  this.nameFromFilename(this._scriptPath);
@@ -4062,16 +4143,22 @@ Expecting one of '${allowedValues.join("', '")}'`);
4062
4143
  /**
4063
4144
  * Parse `argv`, setting options and invoking commands when defined.
4064
4145
  *
4065
- * The default expectation is that the arguments are from node and have the application as argv[0]
4066
- * and the script being run in argv[1], with user parameters after that.
4146
+ * Use parseAsync instead of parse if any of your action handlers are async.
4147
+ *
4148
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
4149
+ *
4150
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
4151
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
4152
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
4153
+ * - `'user'`: just user arguments
4067
4154
  *
4068
4155
  * @example
4069
- * program.parse(process.argv);
4070
- * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
4156
+ * program.parse(); // parse process.argv and auto-detect electron and special node flags
4157
+ * program.parse(process.argv); // assume argv[0] is app and argv[1] is script
4071
4158
  * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
4072
4159
  *
4073
4160
  * @param {string[]} [argv] - optional, defaults to process.argv
4074
- * @param {Object} [parseOptions] - optionally specify style of options with from: node/user/electron
4161
+ * @param {object} [parseOptions] - optionally specify style of options with from: node/user/electron
4075
4162
  * @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
4076
4163
  * @return {Command} `this` command for chaining
4077
4164
  */
@@ -4083,18 +4170,20 @@ Expecting one of '${allowedValues.join("', '")}'`);
4083
4170
  /**
4084
4171
  * Parse `argv`, setting options and invoking commands when defined.
4085
4172
  *
4086
- * Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
4173
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
4087
4174
  *
4088
- * The default expectation is that the arguments are from node and have the application as argv[0]
4089
- * and the script being run in argv[1], with user parameters after that.
4175
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
4176
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
4177
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
4178
+ * - `'user'`: just user arguments
4090
4179
  *
4091
4180
  * @example
4092
- * await program.parseAsync(process.argv);
4093
- * await program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
4181
+ * await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
4182
+ * await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
4094
4183
  * await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
4095
4184
  *
4096
4185
  * @param {string[]} [argv]
4097
- * @param {Object} [parseOptions]
4186
+ * @param {object} [parseOptions]
4098
4187
  * @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
4099
4188
  * @return {Promise}
4100
4189
  */
@@ -4118,7 +4207,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
4118
4207
  return localBin;
4119
4208
  if (sourceExt.includes(path.extname(baseName)))
4120
4209
  return void 0;
4121
- const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
4210
+ const foundExt = sourceExt.find(
4211
+ (ext) => fs.existsSync(`${localBin}${ext}`)
4212
+ );
4122
4213
  if (foundExt)
4123
4214
  return `${localBin}${foundExt}`;
4124
4215
  return void 0;
@@ -4134,14 +4225,23 @@ Expecting one of '${allowedValues.join("', '")}'`);
4134
4225
  } catch (err) {
4135
4226
  resolvedScriptPath = this._scriptPath;
4136
4227
  }
4137
- executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
4228
+ executableDir = path.resolve(
4229
+ path.dirname(resolvedScriptPath),
4230
+ executableDir
4231
+ );
4138
4232
  }
4139
4233
  if (executableDir) {
4140
4234
  let localFile = findFile(executableDir, executableFile);
4141
4235
  if (!localFile && !subcommand._executableFile && this._scriptPath) {
4142
- const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
4236
+ const legacyName = path.basename(
4237
+ this._scriptPath,
4238
+ path.extname(this._scriptPath)
4239
+ );
4143
4240
  if (legacyName !== this._name) {
4144
- localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
4241
+ localFile = findFile(
4242
+ executableDir,
4243
+ `${legacyName}-${subcommand._name}`
4244
+ );
4145
4245
  }
4146
4246
  }
4147
4247
  executableFile = localFile || executableFile;
@@ -4172,12 +4272,18 @@ Expecting one of '${allowedValues.join("', '")}'`);
4172
4272
  });
4173
4273
  }
4174
4274
  const exitCallback = this._exitCallback;
4175
- proc.on("close", (code, _signal) => {
4275
+ proc.on("close", (code) => {
4176
4276
  code = code ?? 1;
4177
4277
  if (!exitCallback) {
4178
4278
  process$1.exit(code);
4179
4279
  } else {
4180
- exitCallback(new CommanderError$2(code, "commander.executeSubCommandAsync", "(close)"));
4280
+ exitCallback(
4281
+ new CommanderError$2(
4282
+ code,
4283
+ "commander.executeSubCommandAsync",
4284
+ "(close)"
4285
+ )
4286
+ );
4181
4287
  }
4182
4288
  });
4183
4289
  proc.on("error", (err) => {
@@ -4194,7 +4300,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
4194
4300
  if (!exitCallback) {
4195
4301
  process$1.exit(1);
4196
4302
  } else {
4197
- const wrappedError = new CommanderError$2(1, "commander.executeSubCommandAsync", "(error)");
4303
+ const wrappedError = new CommanderError$2(
4304
+ 1,
4305
+ "commander.executeSubCommandAsync",
4306
+ "(error)"
4307
+ );
4198
4308
  wrappedError.nestedError = err;
4199
4309
  exitCallback(wrappedError);
4200
4310
  }
@@ -4209,7 +4319,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
4209
4319
  if (!subCommand)
4210
4320
  this.help({ error: true });
4211
4321
  let promiseChain;
4212
- promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
4322
+ promiseChain = this._chainOrCallSubCommandHook(
4323
+ promiseChain,
4324
+ subCommand,
4325
+ "preSubcommand"
4326
+ );
4213
4327
  promiseChain = this._chainOrCall(promiseChain, () => {
4214
4328
  if (subCommand._executableHandler) {
4215
4329
  this._executeSubCommand(subCommand, operands.concat(unknown));
@@ -4234,9 +4348,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
4234
4348
  if (subCommand && !subCommand._executableHandler) {
4235
4349
  subCommand.help();
4236
4350
  }
4237
- return this._dispatchSubcommand(subcommandName, [], [
4238
- ((_a2 = this._getHelpOption()) == null ? void 0 : _a2.long) ?? ((_b2 = this._getHelpOption()) == null ? void 0 : _b2.short) ?? "--help"
4239
- ]);
4351
+ return this._dispatchSubcommand(
4352
+ subcommandName,
4353
+ [],
4354
+ [((_a2 = this._getHelpOption()) == null ? void 0 : _a2.long) ?? ((_b2 = this._getHelpOption()) == null ? void 0 : _b2.short) ?? "--help"]
4355
+ );
4240
4356
  }
4241
4357
  /**
4242
4358
  * Check this.args against expected this.registeredArguments.
@@ -4266,7 +4382,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
4266
4382
  let parsedValue = value;
4267
4383
  if (value !== null && argument2.parseArg) {
4268
4384
  const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument2.name()}'.`;
4269
- parsedValue = this._callParseArg(argument2, value, previous, invalidValueMessage);
4385
+ parsedValue = this._callParseArg(
4386
+ argument2,
4387
+ value,
4388
+ previous,
4389
+ invalidValueMessage
4390
+ );
4270
4391
  }
4271
4392
  return parsedValue;
4272
4393
  };
@@ -4374,7 +4495,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
4374
4495
  }
4375
4496
  if (this._defaultCommandName) {
4376
4497
  this._outputHelpIfRequested(unknown);
4377
- return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
4498
+ return this._dispatchSubcommand(
4499
+ this._defaultCommandName,
4500
+ operands,
4501
+ unknown
4502
+ );
4378
4503
  }
4379
4504
  if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
4380
4505
  this.help({ error: true });
@@ -4393,7 +4518,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
4393
4518
  this._processArguments();
4394
4519
  let promiseChain;
4395
4520
  promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
4396
- promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
4521
+ promiseChain = this._chainOrCall(
4522
+ promiseChain,
4523
+ () => this._actionHandler(this.processedArgs)
4524
+ );
4397
4525
  if (this.parent) {
4398
4526
  promiseChain = this._chainOrCall(promiseChain, () => {
4399
4527
  this.parent.emit(commandEvent, operands, unknown);
@@ -4430,18 +4558,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
4430
4558
  * Find matching command.
4431
4559
  *
4432
4560
  * @private
4561
+ * @return {Command | undefined}
4433
4562
  */
4434
4563
  _findCommand(name) {
4435
4564
  if (!name)
4436
4565
  return void 0;
4437
- return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
4566
+ return this.commands.find(
4567
+ (cmd) => cmd._name === name || cmd._aliases.includes(name)
4568
+ );
4438
4569
  }
4439
4570
  /**
4440
4571
  * Return an option matching `arg` if any.
4441
4572
  *
4442
4573
  * @param {string} arg
4443
4574
  * @return {Option}
4444
- * @package internal use only
4575
+ * @package
4445
4576
  */
4446
4577
  _findOption(arg) {
4447
4578
  return this.options.find((option2) => option2.is(arg));
@@ -4467,15 +4598,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
4467
4598
  * @private
4468
4599
  */
4469
4600
  _checkForConflictingLocalOptions() {
4470
- const definedNonDefaultOptions = this.options.filter(
4471
- (option2) => {
4472
- const optionKey = option2.attributeName();
4473
- if (this.getOptionValue(optionKey) === void 0) {
4474
- return false;
4475
- }
4476
- return this.getOptionValueSource(optionKey) !== "default";
4601
+ const definedNonDefaultOptions = this.options.filter((option2) => {
4602
+ const optionKey = option2.attributeName();
4603
+ if (this.getOptionValue(optionKey) === void 0) {
4604
+ return false;
4477
4605
  }
4478
- );
4606
+ return this.getOptionValueSource(optionKey) !== "default";
4607
+ });
4479
4608
  const optionsWithConflicting = definedNonDefaultOptions.filter(
4480
4609
  (option2) => option2.conflictsWith.length > 0
4481
4610
  );
@@ -4611,7 +4740,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
4611
4740
  /**
4612
4741
  * Return an object containing local option values as key-value pairs.
4613
4742
  *
4614
- * @return {Object}
4743
+ * @return {object}
4615
4744
  */
4616
4745
  opts() {
4617
4746
  if (this._storeOptionsAsProperties) {
@@ -4628,7 +4757,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
4628
4757
  /**
4629
4758
  * Return an object containing merged local and global option values as key-value pairs.
4630
4759
  *
4631
- * @return {Object}
4760
+ * @return {object}
4632
4761
  */
4633
4762
  optsWithGlobals() {
4634
4763
  return this._getCommandAndAncestors().reduce(
@@ -4640,13 +4769,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
4640
4769
  * Display error message and exit (or call exitOverride).
4641
4770
  *
4642
4771
  * @param {string} message
4643
- * @param {Object} [errorOptions]
4772
+ * @param {object} [errorOptions]
4644
4773
  * @param {string} [errorOptions.code] - an id string representing the error
4645
4774
  * @param {number} [errorOptions.exitCode] - used with process.exit
4646
4775
  */
4647
4776
  error(message, errorOptions) {
4648
- this._outputConfiguration.outputError(`${message}
4649
- `, this._outputConfiguration.writeErr);
4777
+ this._outputConfiguration.outputError(
4778
+ `${message}
4779
+ `,
4780
+ this._outputConfiguration.writeErr
4781
+ );
4650
4782
  if (typeof this._showHelpAfterError === "string") {
4651
4783
  this._outputConfiguration.writeErr(`${this._showHelpAfterError}
4652
4784
  `);
@@ -4669,7 +4801,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
4669
4801
  this.options.forEach((option2) => {
4670
4802
  if (option2.envVar && option2.envVar in process$1.env) {
4671
4803
  const optionKey = option2.attributeName();
4672
- if (this.getOptionValue(optionKey) === void 0 || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
4804
+ if (this.getOptionValue(optionKey) === void 0 || ["default", "config", "env"].includes(
4805
+ this.getOptionValueSource(optionKey)
4806
+ )) {
4673
4807
  if (option2.required || option2.optional) {
4674
4808
  this.emit(`optionEnv:${option2.name()}`, process$1.env[option2.envVar]);
4675
4809
  } else {
@@ -4689,9 +4823,18 @@ Expecting one of '${allowedValues.join("', '")}'`);
4689
4823
  const hasCustomOptionValue = (optionKey) => {
4690
4824
  return this.getOptionValue(optionKey) !== void 0 && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
4691
4825
  };
4692
- this.options.filter((option2) => option2.implied !== void 0 && hasCustomOptionValue(option2.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option2.attributeName()), option2)).forEach((option2) => {
4826
+ this.options.filter(
4827
+ (option2) => option2.implied !== void 0 && hasCustomOptionValue(option2.attributeName()) && dualHelper.valueFromOption(
4828
+ this.getOptionValue(option2.attributeName()),
4829
+ option2
4830
+ )
4831
+ ).forEach((option2) => {
4693
4832
  Object.keys(option2.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
4694
- this.setOptionValueWithSource(impliedKey, option2.implied[impliedKey], "implied");
4833
+ this.setOptionValueWithSource(
4834
+ impliedKey,
4835
+ option2.implied[impliedKey],
4836
+ "implied"
4837
+ );
4695
4838
  });
4696
4839
  });
4697
4840
  }
@@ -4736,8 +4879,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
4736
4879
  const findBestOptionFromValue = (option3) => {
4737
4880
  const optionKey = option3.attributeName();
4738
4881
  const optionValue = this.getOptionValue(optionKey);
4739
- const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
4740
- const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
4882
+ const negativeOption = this.options.find(
4883
+ (target) => target.negate && optionKey === target.attributeName()
4884
+ );
4885
+ const positiveOption = this.options.find(
4886
+ (target) => !target.negate && optionKey === target.attributeName()
4887
+ );
4741
4888
  if (negativeOption && (negativeOption.presetArg === void 0 && optionValue === false || negativeOption.presetArg !== void 0 && optionValue === negativeOption.presetArg)) {
4742
4889
  return negativeOption;
4743
4890
  }
@@ -4845,7 +4992,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
4845
4992
  * Set the description.
4846
4993
  *
4847
4994
  * @param {string} [str]
4848
- * @param {Object} [argsDescription]
4995
+ * @param {object} [argsDescription]
4849
4996
  * @return {(string|Command)}
4850
4997
  */
4851
4998
  description(str, argsDescription) {
@@ -4890,7 +5037,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
4890
5037
  const matchingCommand = (_a2 = this.parent) == null ? void 0 : _a2._findCommand(alias);
4891
5038
  if (matchingCommand) {
4892
5039
  const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
4893
- throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
5040
+ throw new Error(
5041
+ `cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`
5042
+ );
4894
5043
  }
4895
5044
  command2._aliases.push(alias);
4896
5045
  return this;
@@ -5034,7 +5183,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
5034
5183
  this.emit(this._getHelpOption().long);
5035
5184
  }
5036
5185
  this.emit("afterHelp", context);
5037
- this._getCommandAndAncestors().forEach((command2) => command2.emit("afterAllHelp", context));
5186
+ this._getCommandAndAncestors().forEach(
5187
+ (command2) => command2.emit("afterAllHelp", context)
5188
+ );
5038
5189
  }
5039
5190
  /**
5040
5191
  * You can pass in flags and a description to customise the built-in help option.
@@ -5067,7 +5218,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
5067
5218
  * Returns null if has been disabled with .helpOption(false).
5068
5219
  *
5069
5220
  * @returns {(Option | null)} the help option
5070
- * @package internal use only
5221
+ * @package
5071
5222
  */
5072
5223
  _getHelpOption() {
5073
5224
  if (this._helpOption === void 0) {
@@ -9916,12 +10067,12 @@ lodash_truncate.exports;
9916
10067
  return symbolToString ? symbolToString.call(value) : "";
9917
10068
  }
9918
10069
  var result = value + "";
9919
- return result == "0" && 1 / value == -Infinity ? "-0" : result;
10070
+ return result == "0" && 1 / value == -INFINITY ? "-0" : result;
9920
10071
  }
9921
10072
  function castSlice(array, start, end) {
9922
10073
  var length = array.length;
9923
10074
  end = end === void 0 ? length : end;
9924
- return end >= length ? array : baseSlice(array, start, end);
10075
+ return !start && end >= length ? array : baseSlice(array, start, end);
9925
10076
  }
9926
10077
  function isObject2(value) {
9927
10078
  var type = typeof value;
@@ -9939,7 +10090,7 @@ lodash_truncate.exports;
9939
10090
  return value === 0 ? value : 0;
9940
10091
  }
9941
10092
  value = toNumber(value);
9942
- if (value === INFINITY || value === -Infinity) {
10093
+ if (value === INFINITY || value === -INFINITY) {
9943
10094
  var sign = value < 0 ? -1 : 1;
9944
10095
  return sign * MAX_INTEGER;
9945
10096
  }
@@ -10883,6 +11034,9 @@ const quotelessJson = (obj) => {
10883
11034
  return json.replace(/"([^"]+)":/g, "$1:");
10884
11035
  };
10885
11036
  class ZodError extends Error {
11037
+ get errors() {
11038
+ return this.issues;
11039
+ }
10886
11040
  constructor(issues) {
10887
11041
  super();
10888
11042
  this.issues = [];
@@ -10901,9 +11055,6 @@ class ZodError extends Error {
10901
11055
  this.name = "ZodError";
10902
11056
  this.issues = issues;
10903
11057
  }
10904
- get errors() {
10905
- return this.issues;
10906
- }
10907
11058
  format(_mapper) {
10908
11059
  const mapper = _mapper || function(issue) {
10909
11060
  return issue.message;
@@ -10940,6 +11091,11 @@ class ZodError extends Error {
10940
11091
  processError(this);
10941
11092
  return fieldErrors;
10942
11093
  }
11094
+ static assert(value) {
11095
+ if (!(value instanceof ZodError)) {
11096
+ throw new Error(`Not a ZodError: ${value}`);
11097
+ }
11098
+ }
10943
11099
  toString() {
10944
11100
  return this.message;
10945
11101
  }
@@ -11082,6 +11238,13 @@ const makeIssue = (params) => {
11082
11238
  ...issueData,
11083
11239
  path: fullPath
11084
11240
  };
11241
+ if (issueData.message !== void 0) {
11242
+ return {
11243
+ ...issueData,
11244
+ path: fullPath,
11245
+ message: issueData.message
11246
+ };
11247
+ }
11085
11248
  let errorMessage = "";
11086
11249
  const maps = errorMaps.filter((m) => !!m).slice().reverse();
11087
11250
  for (const map of maps) {
@@ -11090,20 +11253,24 @@ const makeIssue = (params) => {
11090
11253
  return {
11091
11254
  ...issueData,
11092
11255
  path: fullPath,
11093
- message: issueData.message || errorMessage
11256
+ message: errorMessage
11094
11257
  };
11095
11258
  };
11096
11259
  const EMPTY_PATH = [];
11097
11260
  function addIssueToContext(ctx, issueData) {
11261
+ const overrideMap = getErrorMap();
11098
11262
  const issue = makeIssue({
11099
11263
  issueData,
11100
11264
  data: ctx.data,
11101
11265
  path: ctx.path,
11102
11266
  errorMaps: [
11103
11267
  ctx.common.contextualErrorMap,
11268
+ // contextual error map is first priority
11104
11269
  ctx.schemaErrorMap,
11105
- getErrorMap(),
11106
- errorMap
11270
+ // then schema-bound map if available
11271
+ overrideMap,
11272
+ // then global override map
11273
+ overrideMap === errorMap ? void 0 : errorMap
11107
11274
  // then global default map
11108
11275
  ].filter((x) => !!x)
11109
11276
  });
@@ -11135,9 +11302,11 @@ class ParseStatus {
11135
11302
  static async mergeObjectAsync(status, pairs) {
11136
11303
  const syncPairs = [];
11137
11304
  for (const pair of pairs) {
11305
+ const key = await pair.key;
11306
+ const value = await pair.value;
11138
11307
  syncPairs.push({
11139
- key: await pair.key,
11140
- value: await pair.value
11308
+ key,
11309
+ value
11141
11310
  });
11142
11311
  }
11143
11312
  return ParseStatus.mergeObjectSync(status, syncPairs);
@@ -11170,11 +11339,26 @@ const isAborted = (x) => x.status === "aborted";
11170
11339
  const isDirty = (x) => x.status === "dirty";
11171
11340
  const isValid = (x) => x.status === "valid";
11172
11341
  const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
11342
+ function __classPrivateFieldGet(receiver, state, kind, f) {
11343
+ if (typeof state === "function" ? receiver !== state || true : !state.has(receiver))
11344
+ throw new TypeError("Cannot read private member from an object whose class did not declare it");
11345
+ return state.get(receiver);
11346
+ }
11347
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
11348
+ if (typeof state === "function" ? receiver !== state || true : !state.has(receiver))
11349
+ throw new TypeError("Cannot write private member to an object whose class did not declare it");
11350
+ return state.set(receiver, value), value;
11351
+ }
11352
+ typeof SuppressedError === "function" ? SuppressedError : function(error2, suppressed, message) {
11353
+ var e = new Error(message);
11354
+ return e.name = "SuppressedError", e.error = error2, e.suppressed = suppressed, e;
11355
+ };
11173
11356
  var errorUtil;
11174
11357
  (function(errorUtil2) {
11175
11358
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
11176
11359
  errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
11177
11360
  })(errorUtil || (errorUtil = {}));
11361
+ var _ZodEnum_cache, _ZodNativeEnum_cache;
11178
11362
  class ParseInputLazyPath {
11179
11363
  constructor(parent, value, path2, key) {
11180
11364
  this._cachedPath = [];
@@ -11223,44 +11407,21 @@ function processCreateParams(params) {
11223
11407
  if (errorMap2)
11224
11408
  return { errorMap: errorMap2, description };
11225
11409
  const customMap = (iss, ctx) => {
11226
- if (iss.code !== "invalid_type")
11227
- return { message: ctx.defaultError };
11410
+ var _a2, _b2;
11411
+ const { message } = params;
11412
+ if (iss.code === "invalid_enum_value") {
11413
+ return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
11414
+ }
11228
11415
  if (typeof ctx.data === "undefined") {
11229
- return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
11416
+ return { message: (_a2 = message !== null && message !== void 0 ? message : required_error) !== null && _a2 !== void 0 ? _a2 : ctx.defaultError };
11230
11417
  }
11231
- return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
11418
+ if (iss.code !== "invalid_type")
11419
+ return { message: ctx.defaultError };
11420
+ return { message: (_b2 = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b2 !== void 0 ? _b2 : ctx.defaultError };
11232
11421
  };
11233
11422
  return { errorMap: customMap, description };
11234
11423
  }
11235
11424
  class ZodType {
11236
- constructor(def) {
11237
- this.spa = this.safeParseAsync;
11238
- this._def = def;
11239
- this.parse = this.parse.bind(this);
11240
- this.safeParse = this.safeParse.bind(this);
11241
- this.parseAsync = this.parseAsync.bind(this);
11242
- this.safeParseAsync = this.safeParseAsync.bind(this);
11243
- this.spa = this.spa.bind(this);
11244
- this.refine = this.refine.bind(this);
11245
- this.refinement = this.refinement.bind(this);
11246
- this.superRefine = this.superRefine.bind(this);
11247
- this.optional = this.optional.bind(this);
11248
- this.nullable = this.nullable.bind(this);
11249
- this.nullish = this.nullish.bind(this);
11250
- this.array = this.array.bind(this);
11251
- this.promise = this.promise.bind(this);
11252
- this.or = this.or.bind(this);
11253
- this.and = this.and.bind(this);
11254
- this.transform = this.transform.bind(this);
11255
- this.brand = this.brand.bind(this);
11256
- this.default = this.default.bind(this);
11257
- this.catch = this.catch.bind(this);
11258
- this.describe = this.describe.bind(this);
11259
- this.pipe = this.pipe.bind(this);
11260
- this.readonly = this.readonly.bind(this);
11261
- this.isNullable = this.isNullable.bind(this);
11262
- this.isOptional = this.isOptional.bind(this);
11263
- }
11264
11425
  get description() {
11265
11426
  return this._def.description;
11266
11427
  }
@@ -11324,6 +11485,43 @@ class ZodType {
11324
11485
  const result = this._parseSync({ data, path: ctx.path, parent: ctx });
11325
11486
  return handleResult(ctx, result);
11326
11487
  }
11488
+ "~validate"(data) {
11489
+ var _a2, _b2;
11490
+ const ctx = {
11491
+ common: {
11492
+ issues: [],
11493
+ async: !!this["~standard"].async
11494
+ },
11495
+ path: [],
11496
+ schemaErrorMap: this._def.errorMap,
11497
+ parent: null,
11498
+ data,
11499
+ parsedType: getParsedType(data)
11500
+ };
11501
+ if (!this["~standard"].async) {
11502
+ try {
11503
+ const result = this._parseSync({ data, path: [], parent: ctx });
11504
+ return isValid(result) ? {
11505
+ value: result.value
11506
+ } : {
11507
+ issues: ctx.common.issues
11508
+ };
11509
+ } catch (err) {
11510
+ if ((_b2 = (_a2 = err === null || err === void 0 ? void 0 : err.message) === null || _a2 === void 0 ? void 0 : _a2.toLowerCase()) === null || _b2 === void 0 ? void 0 : _b2.includes("encountered")) {
11511
+ this["~standard"].async = true;
11512
+ }
11513
+ ctx.common = {
11514
+ issues: [],
11515
+ async: true
11516
+ };
11517
+ }
11518
+ }
11519
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
11520
+ value: result.value
11521
+ } : {
11522
+ issues: ctx.common.issues
11523
+ });
11524
+ }
11327
11525
  async parseAsync(data, params) {
11328
11526
  const result = await this.safeParseAsync(data, params);
11329
11527
  if (result.success)
@@ -11401,6 +11599,39 @@ class ZodType {
11401
11599
  superRefine(refinement) {
11402
11600
  return this._refinement(refinement);
11403
11601
  }
11602
+ constructor(def) {
11603
+ this.spa = this.safeParseAsync;
11604
+ this._def = def;
11605
+ this.parse = this.parse.bind(this);
11606
+ this.safeParse = this.safeParse.bind(this);
11607
+ this.parseAsync = this.parseAsync.bind(this);
11608
+ this.safeParseAsync = this.safeParseAsync.bind(this);
11609
+ this.spa = this.spa.bind(this);
11610
+ this.refine = this.refine.bind(this);
11611
+ this.refinement = this.refinement.bind(this);
11612
+ this.superRefine = this.superRefine.bind(this);
11613
+ this.optional = this.optional.bind(this);
11614
+ this.nullable = this.nullable.bind(this);
11615
+ this.nullish = this.nullish.bind(this);
11616
+ this.array = this.array.bind(this);
11617
+ this.promise = this.promise.bind(this);
11618
+ this.or = this.or.bind(this);
11619
+ this.and = this.and.bind(this);
11620
+ this.transform = this.transform.bind(this);
11621
+ this.brand = this.brand.bind(this);
11622
+ this.default = this.default.bind(this);
11623
+ this.catch = this.catch.bind(this);
11624
+ this.describe = this.describe.bind(this);
11625
+ this.pipe = this.pipe.bind(this);
11626
+ this.readonly = this.readonly.bind(this);
11627
+ this.isNullable = this.isNullable.bind(this);
11628
+ this.isOptional = this.isOptional.bind(this);
11629
+ this["~standard"] = {
11630
+ version: 1,
11631
+ vendor: "zod",
11632
+ validate: (data) => this["~validate"](data)
11633
+ };
11634
+ }
11404
11635
  optional() {
11405
11636
  return ZodOptional.create(this, this._def);
11406
11637
  }
@@ -11411,7 +11642,7 @@ class ZodType {
11411
11642
  return this.nullable().optional();
11412
11643
  }
11413
11644
  array() {
11414
- return ZodArray.create(this, this._def);
11645
+ return ZodArray.create(this);
11415
11646
  }
11416
11647
  promise() {
11417
11648
  return ZodPromise.create(this, this._def);
@@ -11476,35 +11707,44 @@ class ZodType {
11476
11707
  }
11477
11708
  }
11478
11709
  const cuidRegex = /^c[^\s-]{8,}$/i;
11479
- const cuid2Regex = /^[a-z][a-z0-9]*$/;
11480
- const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
11710
+ const cuid2Regex = /^[0-9a-z]+$/;
11711
+ const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
11481
11712
  const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
11482
- const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
11713
+ const nanoidRegex = /^[a-z0-9_-]{21}$/i;
11714
+ const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
11715
+ const durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
11716
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
11483
11717
  const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
11484
11718
  let emojiRegex;
11485
- const ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
11486
- const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
11487
- const datetimeRegex = (args) => {
11719
+ const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
11720
+ const ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
11721
+ const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
11722
+ const ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
11723
+ const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
11724
+ const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
11725
+ const dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
11726
+ const dateRegex = new RegExp(`^${dateRegexSource}$`);
11727
+ function timeRegexSource(args) {
11728
+ let regex2 = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
11488
11729
  if (args.precision) {
11489
- if (args.offset) {
11490
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
11491
- } else {
11492
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
11493
- }
11494
- } else if (args.precision === 0) {
11495
- if (args.offset) {
11496
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
11497
- } else {
11498
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
11499
- }
11500
- } else {
11501
- if (args.offset) {
11502
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
11503
- } else {
11504
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
11505
- }
11730
+ regex2 = `${regex2}\\.\\d{${args.precision}}`;
11731
+ } else if (args.precision == null) {
11732
+ regex2 = `${regex2}(\\.\\d+)?`;
11506
11733
  }
11507
- };
11734
+ return regex2;
11735
+ }
11736
+ function timeRegex(args) {
11737
+ return new RegExp(`^${timeRegexSource(args)}$`);
11738
+ }
11739
+ function datetimeRegex(args) {
11740
+ let regex2 = `${dateRegexSource}T${timeRegexSource(args)}`;
11741
+ const opts = [];
11742
+ opts.push(args.local ? `Z?` : `Z`);
11743
+ if (args.offset)
11744
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
11745
+ regex2 = `${regex2}(${opts.join("|")})`;
11746
+ return new RegExp(`^${regex2}$`);
11747
+ }
11508
11748
  function isValidIP(ip, version) {
11509
11749
  if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
11510
11750
  return true;
@@ -11514,6 +11754,33 @@ function isValidIP(ip, version) {
11514
11754
  }
11515
11755
  return false;
11516
11756
  }
11757
+ function isValidJWT(jwt, alg) {
11758
+ if (!jwtRegex.test(jwt))
11759
+ return false;
11760
+ try {
11761
+ const [header] = jwt.split(".");
11762
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
11763
+ const decoded = JSON.parse(atob(base64));
11764
+ if (typeof decoded !== "object" || decoded === null)
11765
+ return false;
11766
+ if (!decoded.typ || !decoded.alg)
11767
+ return false;
11768
+ if (alg && decoded.alg !== alg)
11769
+ return false;
11770
+ return true;
11771
+ } catch (_a2) {
11772
+ return false;
11773
+ }
11774
+ }
11775
+ function isValidCidr(ip, version) {
11776
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
11777
+ return true;
11778
+ }
11779
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
11780
+ return true;
11781
+ }
11782
+ return false;
11783
+ }
11517
11784
  class ZodString extends ZodType {
11518
11785
  _parse(input) {
11519
11786
  if (this._def.coerce) {
@@ -11522,15 +11789,11 @@ class ZodString extends ZodType {
11522
11789
  const parsedType = this._getType(input);
11523
11790
  if (parsedType !== ZodParsedType.string) {
11524
11791
  const ctx2 = this._getOrReturnCtx(input);
11525
- addIssueToContext(
11526
- ctx2,
11527
- {
11528
- code: ZodIssueCode.invalid_type,
11529
- expected: ZodParsedType.string,
11530
- received: ctx2.parsedType
11531
- }
11532
- //
11533
- );
11792
+ addIssueToContext(ctx2, {
11793
+ code: ZodIssueCode.invalid_type,
11794
+ expected: ZodParsedType.string,
11795
+ received: ctx2.parsedType
11796
+ });
11534
11797
  return INVALID;
11535
11798
  }
11536
11799
  const status = new ParseStatus();
@@ -11621,6 +11884,16 @@ class ZodString extends ZodType {
11621
11884
  });
11622
11885
  status.dirty();
11623
11886
  }
11887
+ } else if (check.kind === "nanoid") {
11888
+ if (!nanoidRegex.test(input.data)) {
11889
+ ctx = this._getOrReturnCtx(input, ctx);
11890
+ addIssueToContext(ctx, {
11891
+ validation: "nanoid",
11892
+ code: ZodIssueCode.invalid_string,
11893
+ message: check.message
11894
+ });
11895
+ status.dirty();
11896
+ }
11624
11897
  } else if (check.kind === "cuid") {
11625
11898
  if (!cuidRegex.test(input.data)) {
11626
11899
  ctx = this._getOrReturnCtx(input, ctx);
@@ -11722,6 +11995,38 @@ class ZodString extends ZodType {
11722
11995
  });
11723
11996
  status.dirty();
11724
11997
  }
11998
+ } else if (check.kind === "date") {
11999
+ const regex2 = dateRegex;
12000
+ if (!regex2.test(input.data)) {
12001
+ ctx = this._getOrReturnCtx(input, ctx);
12002
+ addIssueToContext(ctx, {
12003
+ code: ZodIssueCode.invalid_string,
12004
+ validation: "date",
12005
+ message: check.message
12006
+ });
12007
+ status.dirty();
12008
+ }
12009
+ } else if (check.kind === "time") {
12010
+ const regex2 = timeRegex(check);
12011
+ if (!regex2.test(input.data)) {
12012
+ ctx = this._getOrReturnCtx(input, ctx);
12013
+ addIssueToContext(ctx, {
12014
+ code: ZodIssueCode.invalid_string,
12015
+ validation: "time",
12016
+ message: check.message
12017
+ });
12018
+ status.dirty();
12019
+ }
12020
+ } else if (check.kind === "duration") {
12021
+ if (!durationRegex.test(input.data)) {
12022
+ ctx = this._getOrReturnCtx(input, ctx);
12023
+ addIssueToContext(ctx, {
12024
+ validation: "duration",
12025
+ code: ZodIssueCode.invalid_string,
12026
+ message: check.message
12027
+ });
12028
+ status.dirty();
12029
+ }
11725
12030
  } else if (check.kind === "ip") {
11726
12031
  if (!isValidIP(input.data, check.version)) {
11727
12032
  ctx = this._getOrReturnCtx(input, ctx);
@@ -11732,6 +12037,46 @@ class ZodString extends ZodType {
11732
12037
  });
11733
12038
  status.dirty();
11734
12039
  }
12040
+ } else if (check.kind === "jwt") {
12041
+ if (!isValidJWT(input.data, check.alg)) {
12042
+ ctx = this._getOrReturnCtx(input, ctx);
12043
+ addIssueToContext(ctx, {
12044
+ validation: "jwt",
12045
+ code: ZodIssueCode.invalid_string,
12046
+ message: check.message
12047
+ });
12048
+ status.dirty();
12049
+ }
12050
+ } else if (check.kind === "cidr") {
12051
+ if (!isValidCidr(input.data, check.version)) {
12052
+ ctx = this._getOrReturnCtx(input, ctx);
12053
+ addIssueToContext(ctx, {
12054
+ validation: "cidr",
12055
+ code: ZodIssueCode.invalid_string,
12056
+ message: check.message
12057
+ });
12058
+ status.dirty();
12059
+ }
12060
+ } else if (check.kind === "base64") {
12061
+ if (!base64Regex.test(input.data)) {
12062
+ ctx = this._getOrReturnCtx(input, ctx);
12063
+ addIssueToContext(ctx, {
12064
+ validation: "base64",
12065
+ code: ZodIssueCode.invalid_string,
12066
+ message: check.message
12067
+ });
12068
+ status.dirty();
12069
+ }
12070
+ } else if (check.kind === "base64url") {
12071
+ if (!base64urlRegex.test(input.data)) {
12072
+ ctx = this._getOrReturnCtx(input, ctx);
12073
+ addIssueToContext(ctx, {
12074
+ validation: "base64url",
12075
+ code: ZodIssueCode.invalid_string,
12076
+ message: check.message
12077
+ });
12078
+ status.dirty();
12079
+ }
11735
12080
  } else {
11736
12081
  util.assertNever(check);
11737
12082
  }
@@ -11763,6 +12108,9 @@ class ZodString extends ZodType {
11763
12108
  uuid(message) {
11764
12109
  return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
11765
12110
  }
12111
+ nanoid(message) {
12112
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
12113
+ }
11766
12114
  cuid(message) {
11767
12115
  return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
11768
12116
  }
@@ -11772,16 +12120,32 @@ class ZodString extends ZodType {
11772
12120
  ulid(message) {
11773
12121
  return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
11774
12122
  }
12123
+ base64(message) {
12124
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
12125
+ }
12126
+ base64url(message) {
12127
+ return this._addCheck({
12128
+ kind: "base64url",
12129
+ ...errorUtil.errToObj(message)
12130
+ });
12131
+ }
12132
+ jwt(options) {
12133
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
12134
+ }
11775
12135
  ip(options) {
11776
12136
  return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
11777
12137
  }
12138
+ cidr(options) {
12139
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
12140
+ }
11778
12141
  datetime(options) {
11779
- var _a2;
12142
+ var _a2, _b2;
11780
12143
  if (typeof options === "string") {
11781
12144
  return this._addCheck({
11782
12145
  kind: "datetime",
11783
12146
  precision: null,
11784
12147
  offset: false,
12148
+ local: false,
11785
12149
  message: options
11786
12150
  });
11787
12151
  }
@@ -11789,9 +12153,30 @@ class ZodString extends ZodType {
11789
12153
  kind: "datetime",
11790
12154
  precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
11791
12155
  offset: (_a2 = options === null || options === void 0 ? void 0 : options.offset) !== null && _a2 !== void 0 ? _a2 : false,
12156
+ local: (_b2 = options === null || options === void 0 ? void 0 : options.local) !== null && _b2 !== void 0 ? _b2 : false,
12157
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
12158
+ });
12159
+ }
12160
+ date(message) {
12161
+ return this._addCheck({ kind: "date", message });
12162
+ }
12163
+ time(options) {
12164
+ if (typeof options === "string") {
12165
+ return this._addCheck({
12166
+ kind: "time",
12167
+ precision: null,
12168
+ message: options
12169
+ });
12170
+ }
12171
+ return this._addCheck({
12172
+ kind: "time",
12173
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
11792
12174
  ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
11793
12175
  });
11794
12176
  }
12177
+ duration(message) {
12178
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
12179
+ }
11795
12180
  regex(regex2, message) {
11796
12181
  return this._addCheck({
11797
12182
  kind: "regex",
@@ -11843,8 +12228,7 @@ class ZodString extends ZodType {
11843
12228
  });
11844
12229
  }
11845
12230
  /**
11846
- * @deprecated Use z.string().min(1) instead.
11847
- * @see {@link ZodString.min}
12231
+ * Equivalent to `.min(1)`
11848
12232
  */
11849
12233
  nonempty(message) {
11850
12234
  return this.min(1, errorUtil.errToObj(message));
@@ -11870,6 +12254,15 @@ class ZodString extends ZodType {
11870
12254
  get isDatetime() {
11871
12255
  return !!this._def.checks.find((ch) => ch.kind === "datetime");
11872
12256
  }
12257
+ get isDate() {
12258
+ return !!this._def.checks.find((ch) => ch.kind === "date");
12259
+ }
12260
+ get isTime() {
12261
+ return !!this._def.checks.find((ch) => ch.kind === "time");
12262
+ }
12263
+ get isDuration() {
12264
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
12265
+ }
11873
12266
  get isEmail() {
11874
12267
  return !!this._def.checks.find((ch) => ch.kind === "email");
11875
12268
  }
@@ -11882,6 +12275,9 @@ class ZodString extends ZodType {
11882
12275
  get isUUID() {
11883
12276
  return !!this._def.checks.find((ch) => ch.kind === "uuid");
11884
12277
  }
12278
+ get isNANOID() {
12279
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
12280
+ }
11885
12281
  get isCUID() {
11886
12282
  return !!this._def.checks.find((ch) => ch.kind === "cuid");
11887
12283
  }
@@ -11894,6 +12290,15 @@ class ZodString extends ZodType {
11894
12290
  get isIP() {
11895
12291
  return !!this._def.checks.find((ch) => ch.kind === "ip");
11896
12292
  }
12293
+ get isCIDR() {
12294
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
12295
+ }
12296
+ get isBase64() {
12297
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
12298
+ }
12299
+ get isBase64url() {
12300
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
12301
+ }
11897
12302
  get minLength() {
11898
12303
  let min = null;
11899
12304
  for (const ch of this._def.checks) {
@@ -12171,17 +12576,15 @@ class ZodBigInt extends ZodType {
12171
12576
  }
12172
12577
  _parse(input) {
12173
12578
  if (this._def.coerce) {
12174
- input.data = BigInt(input.data);
12579
+ try {
12580
+ input.data = BigInt(input.data);
12581
+ } catch (_a2) {
12582
+ return this._getInvalidInput(input);
12583
+ }
12175
12584
  }
12176
12585
  const parsedType = this._getType(input);
12177
12586
  if (parsedType !== ZodParsedType.bigint) {
12178
- const ctx2 = this._getOrReturnCtx(input);
12179
- addIssueToContext(ctx2, {
12180
- code: ZodIssueCode.invalid_type,
12181
- expected: ZodParsedType.bigint,
12182
- received: ctx2.parsedType
12183
- });
12184
- return INVALID;
12587
+ return this._getInvalidInput(input);
12185
12588
  }
12186
12589
  let ctx = void 0;
12187
12590
  const status = new ParseStatus();
@@ -12228,6 +12631,15 @@ class ZodBigInt extends ZodType {
12228
12631
  }
12229
12632
  return { status: status.value, value: input.data };
12230
12633
  }
12634
+ _getInvalidInput(input) {
12635
+ const ctx = this._getOrReturnCtx(input);
12636
+ addIssueToContext(ctx, {
12637
+ code: ZodIssueCode.invalid_type,
12638
+ expected: ZodParsedType.bigint,
12639
+ received: ctx.parsedType
12640
+ });
12641
+ return INVALID;
12642
+ }
12231
12643
  gte(value, message) {
12232
12644
  return this.setLimit("min", value, true, errorUtil.toString(message));
12233
12645
  }
@@ -12807,9 +13219,10 @@ class ZodObject extends ZodType {
12807
13219
  const syncPairs = [];
12808
13220
  for (const pair of pairs) {
12809
13221
  const key = await pair.key;
13222
+ const value = await pair.value;
12810
13223
  syncPairs.push({
12811
13224
  key,
12812
- value: await pair.value,
13225
+ value,
12813
13226
  alwaysSet: pair.alwaysSet
12814
13227
  });
12815
13228
  }
@@ -13160,15 +13573,25 @@ const getDiscriminator = (type) => {
13160
13573
  } else if (type instanceof ZodEnum) {
13161
13574
  return type.options;
13162
13575
  } else if (type instanceof ZodNativeEnum) {
13163
- return Object.keys(type.enum);
13576
+ return util.objectValues(type.enum);
13164
13577
  } else if (type instanceof ZodDefault) {
13165
13578
  return getDiscriminator(type._def.innerType);
13166
13579
  } else if (type instanceof ZodUndefined) {
13167
13580
  return [void 0];
13168
13581
  } else if (type instanceof ZodNull) {
13169
13582
  return [null];
13583
+ } else if (type instanceof ZodOptional) {
13584
+ return [void 0, ...getDiscriminator(type.unwrap())];
13585
+ } else if (type instanceof ZodNullable) {
13586
+ return [null, ...getDiscriminator(type.unwrap())];
13587
+ } else if (type instanceof ZodBranded) {
13588
+ return getDiscriminator(type.unwrap());
13589
+ } else if (type instanceof ZodReadonly) {
13590
+ return getDiscriminator(type.unwrap());
13591
+ } else if (type instanceof ZodCatch) {
13592
+ return getDiscriminator(type._def.innerType);
13170
13593
  } else {
13171
- return null;
13594
+ return [];
13172
13595
  }
13173
13596
  };
13174
13597
  class ZodDiscriminatedUnion extends ZodType {
@@ -13228,7 +13651,7 @@ class ZodDiscriminatedUnion extends ZodType {
13228
13651
  const optionsMap = /* @__PURE__ */ new Map();
13229
13652
  for (const type of options) {
13230
13653
  const discriminatorValues = getDiscriminator(type.shape[discriminator]);
13231
- if (!discriminatorValues) {
13654
+ if (!discriminatorValues.length) {
13232
13655
  throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
13233
13656
  }
13234
13657
  for (const value of discriminatorValues) {
@@ -13428,7 +13851,8 @@ class ZodRecord extends ZodType {
13428
13851
  for (const key in ctx.data) {
13429
13852
  pairs.push({
13430
13853
  key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
13431
- value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key))
13854
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
13855
+ alwaysSet: key in ctx.data
13432
13856
  });
13433
13857
  }
13434
13858
  if (ctx.common.async) {
@@ -13772,6 +14196,10 @@ function createZodEnum(values, params) {
13772
14196
  });
13773
14197
  }
13774
14198
  class ZodEnum extends ZodType {
14199
+ constructor() {
14200
+ super(...arguments);
14201
+ _ZodEnum_cache.set(this, void 0);
14202
+ }
13775
14203
  _parse(input) {
13776
14204
  if (typeof input.data !== "string") {
13777
14205
  const ctx = this._getOrReturnCtx(input);
@@ -13783,7 +14211,10 @@ class ZodEnum extends ZodType {
13783
14211
  });
13784
14212
  return INVALID;
13785
14213
  }
13786
- if (this._def.values.indexOf(input.data) === -1) {
14214
+ if (!__classPrivateFieldGet(this, _ZodEnum_cache)) {
14215
+ __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values));
14216
+ }
14217
+ if (!__classPrivateFieldGet(this, _ZodEnum_cache).has(input.data)) {
13787
14218
  const ctx = this._getOrReturnCtx(input);
13788
14219
  const expectedValues = this._def.values;
13789
14220
  addIssueToContext(ctx, {
@@ -13819,15 +14250,26 @@ class ZodEnum extends ZodType {
13819
14250
  }
13820
14251
  return enumValues;
13821
14252
  }
13822
- extract(values) {
13823
- return ZodEnum.create(values);
14253
+ extract(values, newDef = this._def) {
14254
+ return ZodEnum.create(values, {
14255
+ ...this._def,
14256
+ ...newDef
14257
+ });
13824
14258
  }
13825
- exclude(values) {
13826
- return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
14259
+ exclude(values, newDef = this._def) {
14260
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
14261
+ ...this._def,
14262
+ ...newDef
14263
+ });
13827
14264
  }
13828
14265
  }
14266
+ _ZodEnum_cache = /* @__PURE__ */ new WeakMap();
13829
14267
  ZodEnum.create = createZodEnum;
13830
14268
  class ZodNativeEnum extends ZodType {
14269
+ constructor() {
14270
+ super(...arguments);
14271
+ _ZodNativeEnum_cache.set(this, void 0);
14272
+ }
13831
14273
  _parse(input) {
13832
14274
  const nativeEnumValues = util.getValidEnumValues(this._def.values);
13833
14275
  const ctx = this._getOrReturnCtx(input);
@@ -13840,7 +14282,10 @@ class ZodNativeEnum extends ZodType {
13840
14282
  });
13841
14283
  return INVALID;
13842
14284
  }
13843
- if (nativeEnumValues.indexOf(input.data) === -1) {
14285
+ if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache)) {
14286
+ __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)));
14287
+ }
14288
+ if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache).has(input.data)) {
13844
14289
  const expectedValues = util.objectValues(nativeEnumValues);
13845
14290
  addIssueToContext(ctx, {
13846
14291
  received: ctx.data,
@@ -13855,6 +14300,7 @@ class ZodNativeEnum extends ZodType {
13855
14300
  return this._def.values;
13856
14301
  }
13857
14302
  }
14303
+ _ZodNativeEnum_cache = /* @__PURE__ */ new WeakMap();
13858
14304
  ZodNativeEnum.create = (values, params) => {
13859
14305
  return new ZodNativeEnum({
13860
14306
  values,
@@ -13918,26 +14364,38 @@ class ZodEffects extends ZodType {
13918
14364
  checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
13919
14365
  if (effect.type === "preprocess") {
13920
14366
  const processed = effect.transform(ctx.data, checkCtx);
13921
- if (ctx.common.issues.length) {
13922
- return {
13923
- status: "dirty",
13924
- value: ctx.data
13925
- };
13926
- }
13927
14367
  if (ctx.common.async) {
13928
- return Promise.resolve(processed).then((processed2) => {
13929
- return this._def.schema._parseAsync({
14368
+ return Promise.resolve(processed).then(async (processed2) => {
14369
+ if (status.value === "aborted")
14370
+ return INVALID;
14371
+ const result = await this._def.schema._parseAsync({
13930
14372
  data: processed2,
13931
14373
  path: ctx.path,
13932
14374
  parent: ctx
13933
14375
  });
14376
+ if (result.status === "aborted")
14377
+ return INVALID;
14378
+ if (result.status === "dirty")
14379
+ return DIRTY(result.value);
14380
+ if (status.value === "dirty")
14381
+ return DIRTY(result.value);
14382
+ return result;
13934
14383
  });
13935
14384
  } else {
13936
- return this._def.schema._parseSync({
14385
+ if (status.value === "aborted")
14386
+ return INVALID;
14387
+ const result = this._def.schema._parseSync({
13937
14388
  data: processed,
13938
14389
  path: ctx.path,
13939
14390
  parent: ctx
13940
14391
  });
14392
+ if (result.status === "aborted")
14393
+ return INVALID;
14394
+ if (result.status === "dirty")
14395
+ return DIRTY(result.value);
14396
+ if (status.value === "dirty")
14397
+ return DIRTY(result.value);
14398
+ return result;
13941
14399
  }
13942
14400
  }
13943
14401
  if (effect.type === "refinement") {
@@ -14226,10 +14684,16 @@ class ZodPipeline extends ZodType {
14226
14684
  class ZodReadonly extends ZodType {
14227
14685
  _parse(input) {
14228
14686
  const result = this._def.innerType._parse(input);
14229
- if (isValid(result)) {
14230
- result.value = Object.freeze(result.value);
14231
- }
14232
- return result;
14687
+ const freeze = (data) => {
14688
+ if (isValid(data)) {
14689
+ data.value = Object.freeze(data.value);
14690
+ }
14691
+ return data;
14692
+ };
14693
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
14694
+ }
14695
+ unwrap() {
14696
+ return this._def.innerType;
14233
14697
  }
14234
14698
  }
14235
14699
  ZodReadonly.create = (type, params) => {
@@ -14239,19 +14703,35 @@ ZodReadonly.create = (type, params) => {
14239
14703
  ...processCreateParams(params)
14240
14704
  });
14241
14705
  };
14242
- const custom = (check, params = {}, fatal) => {
14706
+ function cleanParams(params, data) {
14707
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
14708
+ const p2 = typeof p === "string" ? { message: p } : p;
14709
+ return p2;
14710
+ }
14711
+ function custom(check, _params = {}, fatal) {
14243
14712
  if (check)
14244
14713
  return ZodAny.create().superRefine((data, ctx) => {
14245
14714
  var _a2, _b2;
14246
- if (!check(data)) {
14247
- const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
14248
- const _fatal = (_b2 = (_a2 = p.fatal) !== null && _a2 !== void 0 ? _a2 : fatal) !== null && _b2 !== void 0 ? _b2 : true;
14249
- const p2 = typeof p === "string" ? { message: p } : p;
14250
- ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
14715
+ const r = check(data);
14716
+ if (r instanceof Promise) {
14717
+ return r.then((r2) => {
14718
+ var _a3, _b3;
14719
+ if (!r2) {
14720
+ const params = cleanParams(_params, data);
14721
+ const _fatal = (_b3 = (_a3 = params.fatal) !== null && _a3 !== void 0 ? _a3 : fatal) !== null && _b3 !== void 0 ? _b3 : true;
14722
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
14723
+ }
14724
+ });
14725
+ }
14726
+ if (!r) {
14727
+ const params = cleanParams(_params, data);
14728
+ const _fatal = (_b2 = (_a2 = params.fatal) !== null && _a2 !== void 0 ? _a2 : fatal) !== null && _b2 !== void 0 ? _b2 : true;
14729
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
14251
14730
  }
14731
+ return;
14252
14732
  });
14253
14733
  return ZodAny.create();
14254
- };
14734
+ }
14255
14735
  const late = {
14256
14736
  object: ZodObject.lazycreate
14257
14737
  };
@@ -14370,6 +14850,7 @@ var z = /* @__PURE__ */ Object.freeze({
14370
14850
  ZodParsedType,
14371
14851
  getParsedType,
14372
14852
  ZodType,
14853
+ datetimeRegex,
14373
14854
  ZodString,
14374
14855
  ZodNumber,
14375
14856
  ZodBigInt,
@@ -14464,6 +14945,9 @@ const zCursorV2 = z.object({
14464
14945
  createdAt: z.date(),
14465
14946
  id: z.string()
14466
14947
  });
14948
+ z.object({
14949
+ name: z.string().min(1)
14950
+ });
14467
14951
  const zAttachedByEnumSchema = z.enum(["ai", "human"]);
14468
14952
  const zBookmarkTagSchema = z.object({
14469
14953
  id: z.string(),
@@ -14492,7 +14976,7 @@ var BookmarkTypes = /* @__PURE__ */ ((BookmarkTypes2) => {
14492
14976
  BookmarkTypes2["UNKNOWN"] = "unknown";
14493
14977
  return BookmarkTypes2;
14494
14978
  })(BookmarkTypes || {});
14495
- const zSortOrder = z.enum(["asc", "desc"]);
14979
+ const zSortOrder = z.enum(["asc", "desc", "relevance"]);
14496
14980
  const zAssetTypesSchema = z.enum([
14497
14981
  "screenshot",
14498
14982
  "assetScreenshot",
@@ -14546,7 +15030,8 @@ const zBookmarkedAssetSchema = z.object({
14546
15030
  assetId: z.string(),
14547
15031
  fileName: z.string().nullish(),
14548
15032
  sourceUrl: z.string().nullish(),
14549
- size: z.number().nullish()
15033
+ size: z.number().nullish(),
15034
+ content: z.string().nullish()
14550
15035
  });
14551
15036
  const zBookmarkContentSchema = z.discriminatedUnion("type", [
14552
15037
  zBookmarkedLinkSchema,
@@ -14565,6 +15050,7 @@ const zBareBookmarkSchema = z.object({
14565
15050
  archived: z.boolean(),
14566
15051
  favourited: z.boolean(),
14567
15052
  taggingStatus: z.enum(["success", "failure", "pending"]).nullable(),
15053
+ summarizationStatus: z.enum(["success", "failure", "pending"]).nullable(),
14568
15054
  note: z.string().nullish(),
14569
15055
  summary: z.string().nullish()
14570
15056
  });
@@ -14647,7 +15133,8 @@ z.object({
14647
15133
  // The value is currently not being used, but keeping it so that client can still set it to true for older
14648
15134
  // servers.
14649
15135
  useCursorV2: z.boolean().optional(),
14650
- sortOrder: zSortOrder.optional().default("desc")
15136
+ sortOrder: zSortOrder.exclude(["relevance"]).optional().default("desc"),
15137
+ includeContent: z.boolean().optional().default(false)
14651
15138
  });
14652
15139
  z.object({
14653
15140
  bookmarks: z.array(zBookmarkSchema),
@@ -14669,7 +15156,9 @@ z.object({
14669
15156
  datePublished: z.coerce.date().nullish(),
14670
15157
  dateModified: z.coerce.date().nullish(),
14671
15158
  // Text specific fields (optional)
14672
- text: z.string().nullish()
15159
+ text: z.string().nullish(),
15160
+ // Asset specific fields (optional)
15161
+ assetContent: z.string().nullish()
14673
15162
  });
14674
15163
  z.object({
14675
15164
  // At least one of the two must be set
@@ -14690,7 +15179,45 @@ z.object({
14690
15179
  text: z.string(),
14691
15180
  limit: z.number().max(MAX_NUM_BOOKMARKS_PER_PAGE).optional(),
14692
15181
  cursor: zSearchBookmarksCursor.nullish(),
14693
- sortOrder: zSortOrder.optional().default("desc")
15182
+ sortOrder: zSortOrder.optional().default("relevance"),
15183
+ includeContent: z.boolean().optional().default(false)
15184
+ });
15185
+ z.object({
15186
+ id: z.string(),
15187
+ createdAt: z.date(),
15188
+ modifiedAt: z.date().nullable(),
15189
+ title: z.string().nullish(),
15190
+ tags: z.array(z.string()),
15191
+ description: z.string().nullish(),
15192
+ bannerImageUrl: z.string().nullable(),
15193
+ content: z.discriminatedUnion("type", [
15194
+ z.object({
15195
+ type: z.literal(
15196
+ "link"
15197
+ /* LINK */
15198
+ ),
15199
+ url: z.string(),
15200
+ author: z.string().nullish()
15201
+ }),
15202
+ z.object({
15203
+ type: z.literal(
15204
+ "text"
15205
+ /* TEXT */
15206
+ ),
15207
+ text: z.string()
15208
+ }),
15209
+ z.object({
15210
+ type: z.literal(
15211
+ "asset"
15212
+ /* ASSET */
15213
+ ),
15214
+ assetType: z.enum(["image", "pdf"]),
15215
+ assetId: z.string(),
15216
+ assetUrl: z.string(),
15217
+ fileName: z.string().nullish(),
15218
+ sourceUrl: z.string().nullish()
15219
+ })
15220
+ ])
14694
15221
  });
14695
15222
  const bookmarkCmd = new Command2().name("bookmarks").description("manipulating bookmarks");
14696
15223
  function collect(val, acc) {
@@ -14753,7 +15280,7 @@ bookmarkCmd.command("add").description("creates a new bookmark").option(
14753
15280
  )
14754
15281
  ];
14755
15282
  if (opts.stdin) {
14756
- const text = fs$1.readFileSync(0, "utf-8");
15283
+ const text = require$$3.readFileSync(0, "utf-8");
14757
15284
  promises.push(
14758
15285
  api2.bookmarks.createBookmark.mutate({ type: BookmarkTypes.TEXT, text, title: opts.title }).then((bookmark) => {
14759
15286
  results.push(normalizeBookmark(bookmark));
@@ -14899,7 +15426,7 @@ const whoamiCmd = new Command2().name("whoami").description("returns info about
14899
15426
  )
14900
15427
  );
14901
15428
  });
14902
- var define_import_meta_env_default = { BASE_URL: "/", MODE: "production", DEV: false, PROD: true, SSR: true, CLI_VERSION: "0.23.0" };
15429
+ var define_import_meta_env_default = { BASE_URL: "/", MODE: "production", DEV: false, PROD: true, SSR: true, CLI_VERSION: "0.25.0" };
14903
15430
  const program = new Command2().name("karakeep").description("A CLI interface to interact with the karakeep api").addOption(
14904
15431
  new Option2("--api-key <key>", "the API key to interact with the API").makeOptionMandatory(true).env("KARAKEEP_API_KEY")
14905
15432
  ).addOption(
@@ -14908,7 +15435,7 @@ const program = new Command2().name("karakeep").description("A CLI interface to
14908
15435
  "the address of the server to connect to"
14909
15436
  ).makeOptionMandatory(true).env("KARAKEEP_SERVER_ADDR")
14910
15437
  ).addOption(new Option2("--json", "to output the result as JSON")).version(
14911
- define_import_meta_env_default && "CLI_VERSION" in define_import_meta_env_default ? "0.23.0" : "0.0.0"
15438
+ define_import_meta_env_default && "CLI_VERSION" in define_import_meta_env_default ? "0.25.0" : "0.0.0"
14912
15439
  );
14913
15440
  program.addCommand(bookmarkCmd);
14914
15441
  program.addCommand(listsCmd);