@optique/core 1.0.0-dev.737 → 1.0.0-dev.745

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.
@@ -244,13 +244,23 @@ function createSyncDerivedFromParser(sourceId, options) {
244
244
  return derivedParser.parse(input);
245
245
  },
246
246
  format(value) {
247
- const sourceValues = options.defaultValues();
248
- const derivedParser = options.factory(...sourceValues);
247
+ let derivedParser;
248
+ try {
249
+ const sourceValues = options.defaultValues();
250
+ derivedParser = options.factory(...sourceValues);
251
+ } catch {
252
+ return String(value);
253
+ }
249
254
  return derivedParser.format(value);
250
255
  },
251
256
  *suggest(prefix) {
252
- const sourceValues = options.defaultValues();
253
- const derivedParser = options.factory(...sourceValues);
257
+ let derivedParser;
258
+ try {
259
+ const sourceValues = options.defaultValues();
260
+ derivedParser = options.factory(...sourceValues);
261
+ } catch {
262
+ return;
263
+ }
254
264
  if (isAsyncModeParser(derivedParser) || !derivedParser.suggest) return;
255
265
  yield* derivedParser.suggest(prefix);
256
266
  },
@@ -312,13 +322,23 @@ function createAsyncDerivedFromParserFromAsyncFactory(sourceId, options) {
312
322
  return Promise.resolve(derivedParser.parse(input));
313
323
  },
314
324
  format(value) {
315
- const sourceValues = options.defaultValues();
316
- const derivedParser = options.factory(...sourceValues);
325
+ let derivedParser;
326
+ try {
327
+ const sourceValues = options.defaultValues();
328
+ derivedParser = options.factory(...sourceValues);
329
+ } catch {
330
+ return String(value);
331
+ }
317
332
  return derivedParser.format(value);
318
333
  },
319
334
  async *suggest(prefix) {
320
- const sourceValues = options.defaultValues();
321
- const derivedParser = options.factory(...sourceValues);
335
+ let derivedParser;
336
+ try {
337
+ const sourceValues = options.defaultValues();
338
+ derivedParser = options.factory(...sourceValues);
339
+ } catch {
340
+ return;
341
+ }
322
342
  if (derivedParser.suggest) for await (const suggestion of derivedParser.suggest(prefix)) yield suggestion;
323
343
  },
324
344
  async *[suggestWithDependency](prefix, dependencyValue) {
@@ -378,13 +398,23 @@ function createAsyncDerivedFromParserFromSyncFactory(sourceId, options) {
378
398
  return Promise.resolve(derivedParser.parse(input));
379
399
  },
380
400
  format(value) {
381
- const sourceValues = options.defaultValues();
382
- const derivedParser = options.factory(...sourceValues);
401
+ let derivedParser;
402
+ try {
403
+ const sourceValues = options.defaultValues();
404
+ derivedParser = options.factory(...sourceValues);
405
+ } catch {
406
+ return String(value);
407
+ }
383
408
  return derivedParser.format(value);
384
409
  },
385
410
  async *suggest(prefix) {
386
- const sourceValues = options.defaultValues();
387
- const derivedParser = options.factory(...sourceValues);
411
+ let derivedParser;
412
+ try {
413
+ const sourceValues = options.defaultValues();
414
+ derivedParser = options.factory(...sourceValues);
415
+ } catch {
416
+ return;
417
+ }
388
418
  if (derivedParser.suggest) yield* derivedParser.suggest(prefix);
389
419
  },
390
420
  *[suggestWithDependency](prefix, dependencyValue) {
@@ -454,13 +484,23 @@ function createSyncDerivedParser(sourceId, options) {
454
484
  return derivedParser.parse(input);
455
485
  },
456
486
  format(value) {
457
- const sourceValue = options.defaultValue();
458
- const derivedParser = options.factory(sourceValue);
487
+ let derivedParser;
488
+ try {
489
+ const sourceValue = options.defaultValue();
490
+ derivedParser = options.factory(sourceValue);
491
+ } catch {
492
+ return String(value);
493
+ }
459
494
  return derivedParser.format(value);
460
495
  },
461
496
  *suggest(prefix) {
462
- const sourceValue = options.defaultValue();
463
- const derivedParser = options.factory(sourceValue);
497
+ let derivedParser;
498
+ try {
499
+ const sourceValue = options.defaultValue();
500
+ derivedParser = options.factory(sourceValue);
501
+ } catch {
502
+ return;
503
+ }
464
504
  if (isAsyncModeParser(derivedParser) || !derivedParser.suggest) return;
465
505
  yield* derivedParser.suggest(prefix);
466
506
  },
@@ -518,13 +558,23 @@ function createAsyncDerivedParserFromAsyncFactory(sourceId, options) {
518
558
  return Promise.resolve(derivedParser.parse(input));
519
559
  },
520
560
  format(value) {
521
- const sourceValue = options.defaultValue();
522
- const derivedParser = options.factory(sourceValue);
561
+ let derivedParser;
562
+ try {
563
+ const sourceValue = options.defaultValue();
564
+ derivedParser = options.factory(sourceValue);
565
+ } catch {
566
+ return String(value);
567
+ }
523
568
  return derivedParser.format(value);
524
569
  },
525
570
  async *suggest(prefix) {
526
- const sourceValue = options.defaultValue();
527
- const derivedParser = options.factory(sourceValue);
571
+ let derivedParser;
572
+ try {
573
+ const sourceValue = options.defaultValue();
574
+ derivedParser = options.factory(sourceValue);
575
+ } catch {
576
+ return;
577
+ }
528
578
  if (derivedParser.suggest) for await (const suggestion of derivedParser.suggest(prefix)) yield suggestion;
529
579
  },
530
580
  async *[suggestWithDependency](prefix, dependencyValue) {
@@ -580,13 +630,23 @@ function createAsyncDerivedParserFromSyncFactory(sourceId, options) {
580
630
  return Promise.resolve(derivedParser.parse(input));
581
631
  },
582
632
  format(value) {
583
- const sourceValue = options.defaultValue();
584
- const derivedParser = options.factory(sourceValue);
633
+ let derivedParser;
634
+ try {
635
+ const sourceValue = options.defaultValue();
636
+ derivedParser = options.factory(sourceValue);
637
+ } catch {
638
+ return String(value);
639
+ }
585
640
  return derivedParser.format(value);
586
641
  },
587
642
  async *suggest(prefix) {
588
- const sourceValue = options.defaultValue();
589
- const derivedParser = options.factory(sourceValue);
643
+ let derivedParser;
644
+ try {
645
+ const sourceValue = options.defaultValue();
646
+ derivedParser = options.factory(sourceValue);
647
+ } catch {
648
+ return;
649
+ }
590
650
  if (derivedParser.suggest) yield* derivedParser.suggest(prefix);
591
651
  },
592
652
  *[suggestWithDependency](prefix, dependencyValue) {
@@ -244,13 +244,23 @@ function createSyncDerivedFromParser(sourceId, options) {
244
244
  return derivedParser.parse(input);
245
245
  },
246
246
  format(value) {
247
- const sourceValues = options.defaultValues();
248
- const derivedParser = options.factory(...sourceValues);
247
+ let derivedParser;
248
+ try {
249
+ const sourceValues = options.defaultValues();
250
+ derivedParser = options.factory(...sourceValues);
251
+ } catch {
252
+ return String(value);
253
+ }
249
254
  return derivedParser.format(value);
250
255
  },
251
256
  *suggest(prefix) {
252
- const sourceValues = options.defaultValues();
253
- const derivedParser = options.factory(...sourceValues);
257
+ let derivedParser;
258
+ try {
259
+ const sourceValues = options.defaultValues();
260
+ derivedParser = options.factory(...sourceValues);
261
+ } catch {
262
+ return;
263
+ }
254
264
  if (isAsyncModeParser(derivedParser) || !derivedParser.suggest) return;
255
265
  yield* derivedParser.suggest(prefix);
256
266
  },
@@ -312,13 +322,23 @@ function createAsyncDerivedFromParserFromAsyncFactory(sourceId, options) {
312
322
  return Promise.resolve(derivedParser.parse(input));
313
323
  },
314
324
  format(value) {
315
- const sourceValues = options.defaultValues();
316
- const derivedParser = options.factory(...sourceValues);
325
+ let derivedParser;
326
+ try {
327
+ const sourceValues = options.defaultValues();
328
+ derivedParser = options.factory(...sourceValues);
329
+ } catch {
330
+ return String(value);
331
+ }
317
332
  return derivedParser.format(value);
318
333
  },
319
334
  async *suggest(prefix) {
320
- const sourceValues = options.defaultValues();
321
- const derivedParser = options.factory(...sourceValues);
335
+ let derivedParser;
336
+ try {
337
+ const sourceValues = options.defaultValues();
338
+ derivedParser = options.factory(...sourceValues);
339
+ } catch {
340
+ return;
341
+ }
322
342
  if (derivedParser.suggest) for await (const suggestion of derivedParser.suggest(prefix)) yield suggestion;
323
343
  },
324
344
  async *[suggestWithDependency](prefix, dependencyValue) {
@@ -378,13 +398,23 @@ function createAsyncDerivedFromParserFromSyncFactory(sourceId, options) {
378
398
  return Promise.resolve(derivedParser.parse(input));
379
399
  },
380
400
  format(value) {
381
- const sourceValues = options.defaultValues();
382
- const derivedParser = options.factory(...sourceValues);
401
+ let derivedParser;
402
+ try {
403
+ const sourceValues = options.defaultValues();
404
+ derivedParser = options.factory(...sourceValues);
405
+ } catch {
406
+ return String(value);
407
+ }
383
408
  return derivedParser.format(value);
384
409
  },
385
410
  async *suggest(prefix) {
386
- const sourceValues = options.defaultValues();
387
- const derivedParser = options.factory(...sourceValues);
411
+ let derivedParser;
412
+ try {
413
+ const sourceValues = options.defaultValues();
414
+ derivedParser = options.factory(...sourceValues);
415
+ } catch {
416
+ return;
417
+ }
388
418
  if (derivedParser.suggest) yield* derivedParser.suggest(prefix);
389
419
  },
390
420
  *[suggestWithDependency](prefix, dependencyValue) {
@@ -454,13 +484,23 @@ function createSyncDerivedParser(sourceId, options) {
454
484
  return derivedParser.parse(input);
455
485
  },
456
486
  format(value) {
457
- const sourceValue = options.defaultValue();
458
- const derivedParser = options.factory(sourceValue);
487
+ let derivedParser;
488
+ try {
489
+ const sourceValue = options.defaultValue();
490
+ derivedParser = options.factory(sourceValue);
491
+ } catch {
492
+ return String(value);
493
+ }
459
494
  return derivedParser.format(value);
460
495
  },
461
496
  *suggest(prefix) {
462
- const sourceValue = options.defaultValue();
463
- const derivedParser = options.factory(sourceValue);
497
+ let derivedParser;
498
+ try {
499
+ const sourceValue = options.defaultValue();
500
+ derivedParser = options.factory(sourceValue);
501
+ } catch {
502
+ return;
503
+ }
464
504
  if (isAsyncModeParser(derivedParser) || !derivedParser.suggest) return;
465
505
  yield* derivedParser.suggest(prefix);
466
506
  },
@@ -518,13 +558,23 @@ function createAsyncDerivedParserFromAsyncFactory(sourceId, options) {
518
558
  return Promise.resolve(derivedParser.parse(input));
519
559
  },
520
560
  format(value) {
521
- const sourceValue = options.defaultValue();
522
- const derivedParser = options.factory(sourceValue);
561
+ let derivedParser;
562
+ try {
563
+ const sourceValue = options.defaultValue();
564
+ derivedParser = options.factory(sourceValue);
565
+ } catch {
566
+ return String(value);
567
+ }
523
568
  return derivedParser.format(value);
524
569
  },
525
570
  async *suggest(prefix) {
526
- const sourceValue = options.defaultValue();
527
- const derivedParser = options.factory(sourceValue);
571
+ let derivedParser;
572
+ try {
573
+ const sourceValue = options.defaultValue();
574
+ derivedParser = options.factory(sourceValue);
575
+ } catch {
576
+ return;
577
+ }
528
578
  if (derivedParser.suggest) for await (const suggestion of derivedParser.suggest(prefix)) yield suggestion;
529
579
  },
530
580
  async *[suggestWithDependency](prefix, dependencyValue) {
@@ -580,13 +630,23 @@ function createAsyncDerivedParserFromSyncFactory(sourceId, options) {
580
630
  return Promise.resolve(derivedParser.parse(input));
581
631
  },
582
632
  format(value) {
583
- const sourceValue = options.defaultValue();
584
- const derivedParser = options.factory(sourceValue);
633
+ let derivedParser;
634
+ try {
635
+ const sourceValue = options.defaultValue();
636
+ derivedParser = options.factory(sourceValue);
637
+ } catch {
638
+ return String(value);
639
+ }
585
640
  return derivedParser.format(value);
586
641
  },
587
642
  async *suggest(prefix) {
588
- const sourceValue = options.defaultValue();
589
- const derivedParser = options.factory(sourceValue);
643
+ let derivedParser;
644
+ try {
645
+ const sourceValue = options.defaultValue();
646
+ derivedParser = options.factory(sourceValue);
647
+ } catch {
648
+ return;
649
+ }
590
650
  if (derivedParser.suggest) yield* derivedParser.suggest(prefix);
591
651
  },
592
652
  *[suggestWithDependency](prefix, dependencyValue) {
@@ -91,6 +91,16 @@ function choice(choices, options = {}) {
91
91
  const stringChoices = choices;
92
92
  const stringOptions = options;
93
93
  const normalizedValues = stringOptions.caseInsensitive ? stringChoices.map((v) => v.toLowerCase()) : stringChoices;
94
+ if (stringOptions.caseInsensitive) {
95
+ const seen = /* @__PURE__ */ new Map();
96
+ for (let i = 0; i < stringChoices.length; i++) {
97
+ const nv = normalizedValues[i];
98
+ const original = stringChoices[i];
99
+ const prev = seen.get(nv);
100
+ if (prev !== void 0 && prev !== original) throw new TypeError(`Ambiguous choices for case-insensitive matching: ${JSON.stringify(prev)} and ${JSON.stringify(original)} both normalize to ${JSON.stringify(nv)}.`);
101
+ seen.set(nv, original);
102
+ }
103
+ }
94
104
  return {
95
105
  $mode: "sync",
96
106
  metavar,
@@ -206,6 +206,8 @@ declare function isValueParser<M extends Mode, T>(object: unknown): object is Va
206
206
  * @param options Configuration options for the choice parser.
207
207
  * @returns A {@link ValueParser} that checks if the input matches one of the
208
208
  * specified values.
209
+ * @throws {TypeError} If `caseInsensitive` is `true` and multiple choices
210
+ * normalize to the same lowercase value.
209
211
  */
210
212
  declare function choice<const T extends string>(choices: readonly T[], options?: ChoiceOptionsString): ValueParser<"sync", T>;
211
213
  /**
@@ -206,6 +206,8 @@ declare function isValueParser<M extends Mode, T>(object: unknown): object is Va
206
206
  * @param options Configuration options for the choice parser.
207
207
  * @returns A {@link ValueParser} that checks if the input matches one of the
208
208
  * specified values.
209
+ * @throws {TypeError} If `caseInsensitive` is `true` and multiple choices
210
+ * normalize to the same lowercase value.
209
211
  */
210
212
  declare function choice<const T extends string>(choices: readonly T[], options?: ChoiceOptionsString): ValueParser<"sync", T>;
211
213
  /**
@@ -91,6 +91,16 @@ function choice(choices, options = {}) {
91
91
  const stringChoices = choices;
92
92
  const stringOptions = options;
93
93
  const normalizedValues = stringOptions.caseInsensitive ? stringChoices.map((v) => v.toLowerCase()) : stringChoices;
94
+ if (stringOptions.caseInsensitive) {
95
+ const seen = /* @__PURE__ */ new Map();
96
+ for (let i = 0; i < stringChoices.length; i++) {
97
+ const nv = normalizedValues[i];
98
+ const original = stringChoices[i];
99
+ const prev = seen.get(nv);
100
+ if (prev !== void 0 && prev !== original) throw new TypeError(`Ambiguous choices for case-insensitive matching: ${JSON.stringify(prev)} and ${JSON.stringify(original)} both normalize to ${JSON.stringify(nv)}.`);
101
+ seen.set(nv, original);
102
+ }
103
+ }
94
104
  return {
95
105
  $mode: "sync",
96
106
  metavar,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.737+e9077af1",
3
+ "version": "1.0.0-dev.745+a12a4fbd",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",