@eliya-oss/agent-diff 0.1.0-alpha.17 → 0.1.0-alpha.19
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.
- package/CHANGELOG.md +12 -0
- package/README.md +5 -2
- package/dist/main.js +1170 -94
- package/package.json +5 -3
package/dist/main.js
CHANGED
|
@@ -458,6 +458,38 @@ function isNumber(input) {
|
|
|
458
458
|
return typeof input === "number";
|
|
459
459
|
}
|
|
460
460
|
/**
|
|
461
|
+
* Checks whether a value is a `boolean`.
|
|
462
|
+
*
|
|
463
|
+
* **When to use**
|
|
464
|
+
*
|
|
465
|
+
* Use when you need a `Predicate` guard to narrow an `unknown` value to a
|
|
466
|
+
* boolean.
|
|
467
|
+
*
|
|
468
|
+
* **Details**
|
|
469
|
+
*
|
|
470
|
+
* Uses `typeof input === "boolean"`.
|
|
471
|
+
*
|
|
472
|
+
* **Example** (Guarding booleans)
|
|
473
|
+
*
|
|
474
|
+
* ```ts
|
|
475
|
+
* import { Predicate } from "effect"
|
|
476
|
+
*
|
|
477
|
+
* const data: unknown = true
|
|
478
|
+
*
|
|
479
|
+
* if (Predicate.isBoolean(data)) {
|
|
480
|
+
* console.log(data ? "yes" : "no")
|
|
481
|
+
* }
|
|
482
|
+
* ```
|
|
483
|
+
*
|
|
484
|
+
* @see {@link isString}
|
|
485
|
+
* @see {@link isNumber}
|
|
486
|
+
* @category guards
|
|
487
|
+
* @since 2.0.0
|
|
488
|
+
*/
|
|
489
|
+
function isBoolean(input) {
|
|
490
|
+
return typeof input === "boolean";
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
461
493
|
* Checks whether a value is a `function`.
|
|
462
494
|
*
|
|
463
495
|
* **When to use**
|
|
@@ -489,6 +521,38 @@ function isFunction(input) {
|
|
|
489
521
|
return typeof input === "function";
|
|
490
522
|
}
|
|
491
523
|
/**
|
|
524
|
+
* Checks whether a value is not `null` and not `undefined`.
|
|
525
|
+
*
|
|
526
|
+
* **When to use**
|
|
527
|
+
*
|
|
528
|
+
* Use when you need a `Predicate` refinement that filters out nullish values
|
|
529
|
+
* but keeps other falsy ones.
|
|
530
|
+
*
|
|
531
|
+
* **Details**
|
|
532
|
+
*
|
|
533
|
+
* Uses `input != null`.
|
|
534
|
+
*
|
|
535
|
+
* **Example** (Filtering non-nullish values)
|
|
536
|
+
*
|
|
537
|
+
* ```ts
|
|
538
|
+
* import { Predicate } from "effect"
|
|
539
|
+
*
|
|
540
|
+
* const values = [0, null, "", undefined]
|
|
541
|
+
* const present = values.filter(Predicate.isNotNullish)
|
|
542
|
+
*
|
|
543
|
+
* console.log(present)
|
|
544
|
+
* ```
|
|
545
|
+
*
|
|
546
|
+
* @see {@link isNullish}
|
|
547
|
+
* @see {@link isNotNull}
|
|
548
|
+
* @see {@link isNotUndefined}
|
|
549
|
+
* @category guards
|
|
550
|
+
* @since 4.0.0
|
|
551
|
+
*/
|
|
552
|
+
function isNotNullish(input) {
|
|
553
|
+
return input != null;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
492
556
|
* Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions).
|
|
493
557
|
*
|
|
494
558
|
* **When to use**
|
|
@@ -5437,8 +5501,22 @@ const failCauseSync$1 = (evaluate) => suspend(() => failCause$1(internalCall(eva
|
|
|
5437
5501
|
/** @internal */
|
|
5438
5502
|
const die = (defect) => exitDie(defect);
|
|
5439
5503
|
/** @internal */
|
|
5504
|
+
const failSync = (error) => suspend(() => fail$2(internalCall(error)));
|
|
5505
|
+
/** @internal */
|
|
5440
5506
|
const void_$2 = /*#__PURE__*/ succeed$2(void 0);
|
|
5441
5507
|
/** @internal */
|
|
5508
|
+
const try_$1 = (options) => {
|
|
5509
|
+
const evaluate = typeof options === "function" ? options : options.try;
|
|
5510
|
+
const catcher = typeof options === "function" ? (cause) => new UnknownError(cause, "An error occurred in Effect.try") : options.catch;
|
|
5511
|
+
return suspend(() => {
|
|
5512
|
+
try {
|
|
5513
|
+
return succeed$2(internalCall(evaluate));
|
|
5514
|
+
} catch (err) {
|
|
5515
|
+
return fail$2(internalCall(() => catcher(err)));
|
|
5516
|
+
}
|
|
5517
|
+
});
|
|
5518
|
+
};
|
|
5519
|
+
/** @internal */
|
|
5442
5520
|
const promise$1 = (evaluate) => callbackOptions(function(resume, signal) {
|
|
5443
5521
|
internalCall(() => evaluate(signal)).then((a) => resume(succeed$2(a)), (e) => resume(die(e)));
|
|
5444
5522
|
}, evaluate.length !== 0);
|
|
@@ -5557,6 +5635,40 @@ const makeFn = (name, bodyOrOptions, defError, pipeables, addSpan, spanOptions)
|
|
|
5557
5635
|
}));
|
|
5558
5636
|
});
|
|
5559
5637
|
};
|
|
5638
|
+
/** @internal */
|
|
5639
|
+
const fnUntracedEager$1 = (body, ...pipeables) => defineFunctionLength(body.length, pipeables.length === 0 ? function() {
|
|
5640
|
+
return fromIteratorEagerUnsafe(() => body.apply(this, arguments));
|
|
5641
|
+
} : function() {
|
|
5642
|
+
let effect = fromIteratorEagerUnsafe(() => body.apply(this, arguments));
|
|
5643
|
+
for (const pipeable of pipeables) effect = pipeable(effect);
|
|
5644
|
+
return effect;
|
|
5645
|
+
});
|
|
5646
|
+
const fromIteratorEagerUnsafe = (evaluate) => {
|
|
5647
|
+
try {
|
|
5648
|
+
const iterator = evaluate();
|
|
5649
|
+
let value = void 0;
|
|
5650
|
+
while (true) {
|
|
5651
|
+
const state = iterator.next(value);
|
|
5652
|
+
if (state.done) return succeed$2(state.value);
|
|
5653
|
+
const primitive = state.value;
|
|
5654
|
+
if (primitive && primitive._tag === "Success") {
|
|
5655
|
+
value = primitive.value;
|
|
5656
|
+
continue;
|
|
5657
|
+
} else if (primitive && primitive._tag === "Failure") return state.value;
|
|
5658
|
+
else {
|
|
5659
|
+
let isFirstExecution = true;
|
|
5660
|
+
return suspend(() => {
|
|
5661
|
+
if (isFirstExecution) {
|
|
5662
|
+
isFirstExecution = false;
|
|
5663
|
+
return flatMap$1(state.value, (value) => fromIteratorUnsafe(iterator, value));
|
|
5664
|
+
} else return suspend(() => fromIteratorUnsafe(evaluate()));
|
|
5665
|
+
});
|
|
5666
|
+
}
|
|
5667
|
+
}
|
|
5668
|
+
} catch (error) {
|
|
5669
|
+
return die(error);
|
|
5670
|
+
}
|
|
5671
|
+
};
|
|
5560
5672
|
const fromIteratorUnsafe = /*#__PURE__*/ makePrimitive({
|
|
5561
5673
|
op: "Iterator",
|
|
5562
5674
|
single: false,
|
|
@@ -5673,6 +5785,13 @@ const OnFailureProto = /*#__PURE__*/ makePrimitiveProto({
|
|
|
5673
5785
|
}
|
|
5674
5786
|
});
|
|
5675
5787
|
/** @internal */
|
|
5788
|
+
const catchCauseFilter = /*#__PURE__*/ dual(3, (self, filter, f) => catchCause$1(self, (cause) => {
|
|
5789
|
+
const eb = filter(cause);
|
|
5790
|
+
return isFailure$1(eb) ? failCause$1(eb.failure) : internalCall(() => f(eb.success, cause));
|
|
5791
|
+
}));
|
|
5792
|
+
/** @internal */
|
|
5793
|
+
const catch_ = /*#__PURE__*/ dual(2, (self, f) => catchCauseFilter(self, findError, (e) => f(e)));
|
|
5794
|
+
/** @internal */
|
|
5676
5795
|
const catchIf = /*#__PURE__*/ dual((args) => isEffect(args[0]), (self, predicate, f, orElse) => catchCause$1(self, (cause) => {
|
|
5677
5796
|
const error = findError(cause);
|
|
5678
5797
|
if (isFailure$1(error)) return failCause$1(error.failure);
|
|
@@ -5685,6 +5804,8 @@ const catchTag$1 = /*#__PURE__*/ dual((args) => isEffect(args[0]), (self, k, f,
|
|
|
5685
5804
|
return catchIf(self, pred, f, orElse);
|
|
5686
5805
|
});
|
|
5687
5806
|
/** @internal */
|
|
5807
|
+
const mapError$1 = /*#__PURE__*/ dual(2, (self, f) => catch_(self, (error) => failSync(() => f(error))));
|
|
5808
|
+
/** @internal */
|
|
5688
5809
|
const exit$2 = (self) => effectIsExit(self) ? exitSucceed(self) : exitPrimitive(self);
|
|
5689
5810
|
const exitPrimitive = /*#__PURE__*/ makePrimitive({
|
|
5690
5811
|
op: "Exit",
|
|
@@ -6346,6 +6467,39 @@ const map$1 = causeMap;
|
|
|
6346
6467
|
const squash = causeSquash;
|
|
6347
6468
|
Service()("effect/Cause/StackTrace");
|
|
6348
6469
|
Service()("effect/Cause/InterruptorStackTrace");
|
|
6470
|
+
//#endregion
|
|
6471
|
+
//#region node_modules/.pnpm/effect@4.0.0-beta.102/node_modules/effect/dist/Exit.js
|
|
6472
|
+
/**
|
|
6473
|
+
* Creates a failed Exit from a Cause.
|
|
6474
|
+
*
|
|
6475
|
+
* **When to use**
|
|
6476
|
+
*
|
|
6477
|
+
* Use when you already have a `Cause<E>` and want to wrap it in an Exit
|
|
6478
|
+
* for advanced error handling where you need full control over the Cause
|
|
6479
|
+
* structure.
|
|
6480
|
+
*
|
|
6481
|
+
* **Details**
|
|
6482
|
+
*
|
|
6483
|
+
* Returns a `Failure<never, E>`. If you only have an error value, use
|
|
6484
|
+
* {@link fail} instead.
|
|
6485
|
+
*
|
|
6486
|
+
* **Example** (Creating a failed Exit from a Cause)
|
|
6487
|
+
*
|
|
6488
|
+
* ```ts
|
|
6489
|
+
* import { Cause, Exit } from "effect"
|
|
6490
|
+
*
|
|
6491
|
+
* const cause = Cause.fail("Something went wrong")
|
|
6492
|
+
* const exit = Exit.failCause(cause)
|
|
6493
|
+
* console.log(Exit.isFailure(exit)) // true
|
|
6494
|
+
* ```
|
|
6495
|
+
*
|
|
6496
|
+
* @see {@link fail} to create a Failure from a plain error value
|
|
6497
|
+
* @see {@link die} to create a Failure from a defect
|
|
6498
|
+
*
|
|
6499
|
+
* @category constructors
|
|
6500
|
+
* @since 2.0.0
|
|
6501
|
+
*/
|
|
6502
|
+
const failCause = exitFailCause;
|
|
6349
6503
|
/**
|
|
6350
6504
|
* Creates a failed Exit from a typed error value.
|
|
6351
6505
|
*
|
|
@@ -7450,6 +7604,7 @@ const fail = fail$2;
|
|
|
7450
7604
|
* @since 2.0.0
|
|
7451
7605
|
*/
|
|
7452
7606
|
const failCauseSync = failCauseSync$1;
|
|
7607
|
+
const try_ = try_$1;
|
|
7453
7608
|
/**
|
|
7454
7609
|
* Chains effects to produce new `Effect` instances, useful for combining
|
|
7455
7610
|
* operations that depend on previous results.
|
|
@@ -7518,6 +7673,49 @@ const failCauseSync = failCauseSync$1;
|
|
|
7518
7673
|
*/
|
|
7519
7674
|
const flatMap = flatMap$1;
|
|
7520
7675
|
/**
|
|
7676
|
+
* Transforms an effect to encapsulate both failure and success using the `Exit`
|
|
7677
|
+
* data type.
|
|
7678
|
+
*
|
|
7679
|
+
* **When to use**
|
|
7680
|
+
*
|
|
7681
|
+
* Use when you need to inspect the full outcome, including typed failures, defects,
|
|
7682
|
+
* and interruptions.
|
|
7683
|
+
*
|
|
7684
|
+
* **Details**
|
|
7685
|
+
*
|
|
7686
|
+
* `exit` wraps an effect's success or failure inside an `Exit` type, allowing
|
|
7687
|
+
* you to handle both cases explicitly.
|
|
7688
|
+
*
|
|
7689
|
+
* The resulting effect cannot fail because the failure is encapsulated within
|
|
7690
|
+
* the `Exit.Failure` type. The error type is set to `never`, indicating that
|
|
7691
|
+
* the effect is structured to never fail directly.
|
|
7692
|
+
*
|
|
7693
|
+
* **Example** (Capturing completion as Exit)
|
|
7694
|
+
*
|
|
7695
|
+
* ```ts
|
|
7696
|
+
* import { Effect } from "effect"
|
|
7697
|
+
*
|
|
7698
|
+
* const success = Effect.succeed(42)
|
|
7699
|
+
* const failure = Effect.fail("Something went wrong")
|
|
7700
|
+
*
|
|
7701
|
+
* const program1 = Effect.exit(success)
|
|
7702
|
+
* const program2 = Effect.exit(failure)
|
|
7703
|
+
*
|
|
7704
|
+
* Effect.runPromise(program1).then(console.log)
|
|
7705
|
+
* // { _id: 'Exit', _tag: 'Success', value: 42 }
|
|
7706
|
+
*
|
|
7707
|
+
* Effect.runPromise(program2).then(console.log)
|
|
7708
|
+
* // { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Something went wrong' } }
|
|
7709
|
+
* ```
|
|
7710
|
+
*
|
|
7711
|
+
* @see {@link option} for a version that uses `Option` instead.
|
|
7712
|
+
* @see {@link result} for a version that uses `Result` instead.
|
|
7713
|
+
*
|
|
7714
|
+
* @category outcome encapsulation
|
|
7715
|
+
* @since 2.0.0
|
|
7716
|
+
*/
|
|
7717
|
+
const exit$1 = exit$2;
|
|
7718
|
+
/**
|
|
7521
7719
|
* Transforms the value inside an effect by applying a function to it.
|
|
7522
7720
|
*
|
|
7523
7721
|
* **When to use**
|
|
@@ -7660,6 +7858,45 @@ const catchTag = catchTag$1;
|
|
|
7660
7858
|
*/
|
|
7661
7859
|
const catchCause = catchCause$1;
|
|
7662
7860
|
/**
|
|
7861
|
+
* Transforms the failure value of an effect without changing its success value.
|
|
7862
|
+
*
|
|
7863
|
+
* **When to use**
|
|
7864
|
+
*
|
|
7865
|
+
* Use to translate an `Effect`'s typed failures while leaving successful values
|
|
7866
|
+
* unchanged.
|
|
7867
|
+
*
|
|
7868
|
+
* **Details**
|
|
7869
|
+
*
|
|
7870
|
+
* Only the failure channel is transformed. The success channel and requirements
|
|
7871
|
+
* are preserved.
|
|
7872
|
+
*
|
|
7873
|
+
* **Example** (Transforming the error channel)
|
|
7874
|
+
*
|
|
7875
|
+
* ```ts
|
|
7876
|
+
* import { Data, Effect } from "effect"
|
|
7877
|
+
*
|
|
7878
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
7879
|
+
*
|
|
7880
|
+
* // ┌─── Effect<number, string, never>
|
|
7881
|
+
* // ▼
|
|
7882
|
+
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
7883
|
+
*
|
|
7884
|
+
* // ┌─── Effect<number, TaskError, never>
|
|
7885
|
+
* // ▼
|
|
7886
|
+
* const mapped = Effect.mapError(
|
|
7887
|
+
* simulatedTask,
|
|
7888
|
+
* (message) => new TaskError({ message })
|
|
7889
|
+
* )
|
|
7890
|
+
* ```
|
|
7891
|
+
*
|
|
7892
|
+
* @see {@link map} for a version that operates on the success channel.
|
|
7893
|
+
* @see {@link mapBoth} for a version that operates on both channels.
|
|
7894
|
+
*
|
|
7895
|
+
* @category error handling
|
|
7896
|
+
* @since 2.0.0
|
|
7897
|
+
*/
|
|
7898
|
+
const mapError = mapError$1;
|
|
7899
|
+
/**
|
|
7663
7900
|
* Returns an effect that suspends the current fiber for the specified duration
|
|
7664
7901
|
* without blocking a JavaScript thread.
|
|
7665
7902
|
*
|
|
@@ -8109,6 +8346,32 @@ const mapEager = mapEager$1;
|
|
|
8109
8346
|
* @since 4.0.0
|
|
8110
8347
|
*/
|
|
8111
8348
|
const flatMapEager = flatMapEager$1;
|
|
8349
|
+
/**
|
|
8350
|
+
* Creates untraced function effects with eager evaluation optimization.
|
|
8351
|
+
*
|
|
8352
|
+
* **Details**
|
|
8353
|
+
*
|
|
8354
|
+
* Executes generator functions eagerly when all yielded effects are synchronous,
|
|
8355
|
+
* stopping at the first async effect and deferring to normal execution.
|
|
8356
|
+
*
|
|
8357
|
+
* **Example** (Defining eager untraced effect functions)
|
|
8358
|
+
*
|
|
8359
|
+
* ```ts
|
|
8360
|
+
* import { Effect } from "effect"
|
|
8361
|
+
*
|
|
8362
|
+
* const computation = Effect.fnUntracedEager(function*() {
|
|
8363
|
+
* yield* Effect.succeed(1)
|
|
8364
|
+
* yield* Effect.succeed(2)
|
|
8365
|
+
* return "computed eagerly"
|
|
8366
|
+
* })
|
|
8367
|
+
*
|
|
8368
|
+
* const effect = computation() // Executed immediately if all effects are sync
|
|
8369
|
+
* ```
|
|
8370
|
+
*
|
|
8371
|
+
* @category eager
|
|
8372
|
+
* @since 4.0.0
|
|
8373
|
+
*/
|
|
8374
|
+
const fnUntracedEager = fnUntracedEager$1;
|
|
8112
8375
|
//#endregion
|
|
8113
8376
|
//#region node_modules/.pnpm/effect@4.0.0-beta.102/node_modules/effect/dist/internal/schema/annotations.js
|
|
8114
8377
|
/** @internal */
|
|
@@ -8309,6 +8572,72 @@ var Pointer = class extends Base$1 {
|
|
|
8309
8572
|
}
|
|
8310
8573
|
};
|
|
8311
8574
|
/**
|
|
8575
|
+
* Represents a schema issue produced when a required key or tuple index is missing from the input.
|
|
8576
|
+
*
|
|
8577
|
+
* **When to use**
|
|
8578
|
+
*
|
|
8579
|
+
* Use when you need to detect absent fields in struct/tuple validation.
|
|
8580
|
+
*
|
|
8581
|
+
* **Details**
|
|
8582
|
+
*
|
|
8583
|
+
* - Has no `actual` value — {@link getActual} returns `Option.none()`.
|
|
8584
|
+
* - `annotations` may contain a custom `messageMissingKey` for formatting.
|
|
8585
|
+
*
|
|
8586
|
+
* @see {@link Pointer} — wraps this issue with the missing key's path
|
|
8587
|
+
* @see {@link UnexpectedKey} — the opposite case (extra key present)
|
|
8588
|
+
*
|
|
8589
|
+
* @category models
|
|
8590
|
+
* @since 4.0.0
|
|
8591
|
+
*/
|
|
8592
|
+
var MissingKey = class extends Base$1 {
|
|
8593
|
+
_tag = "MissingKey";
|
|
8594
|
+
/**
|
|
8595
|
+
* The metadata for the issue.
|
|
8596
|
+
*/
|
|
8597
|
+
annotations;
|
|
8598
|
+
constructor(annotations) {
|
|
8599
|
+
super();
|
|
8600
|
+
this.annotations = annotations;
|
|
8601
|
+
}
|
|
8602
|
+
};
|
|
8603
|
+
/**
|
|
8604
|
+
* Represents a schema issue produced when an input object or tuple contains a key/index not
|
|
8605
|
+
* declared by the schema.
|
|
8606
|
+
*
|
|
8607
|
+
* **When to use**
|
|
8608
|
+
*
|
|
8609
|
+
* Use when you need to detect excess properties during strict struct/tuple
|
|
8610
|
+
* validation.
|
|
8611
|
+
*
|
|
8612
|
+
* **Details**
|
|
8613
|
+
*
|
|
8614
|
+
* - `actual` is the raw value at the unexpected key (plain `unknown`).
|
|
8615
|
+
* - `ast` is the schema that was being validated against.
|
|
8616
|
+
* - `annotations` on `ast` may contain a custom `messageUnexpectedKey`.
|
|
8617
|
+
*
|
|
8618
|
+
* @see {@link MissingKey} — the opposite case (required key absent)
|
|
8619
|
+
* @see {@link Pointer} — wraps this issue with the unexpected key's path
|
|
8620
|
+
*
|
|
8621
|
+
* @category models
|
|
8622
|
+
* @since 4.0.0
|
|
8623
|
+
*/
|
|
8624
|
+
var UnexpectedKey = class extends Base$1 {
|
|
8625
|
+
_tag = "UnexpectedKey";
|
|
8626
|
+
/**
|
|
8627
|
+
* The schema that caused the issue.
|
|
8628
|
+
*/
|
|
8629
|
+
ast;
|
|
8630
|
+
/**
|
|
8631
|
+
* The input value that caused the issue.
|
|
8632
|
+
*/
|
|
8633
|
+
actual;
|
|
8634
|
+
constructor(ast, actual) {
|
|
8635
|
+
super();
|
|
8636
|
+
this.ast = ast;
|
|
8637
|
+
this.actual = actual;
|
|
8638
|
+
}
|
|
8639
|
+
};
|
|
8640
|
+
/**
|
|
8312
8641
|
* Represents a schema issue that groups multiple child issues under a single schema node.
|
|
8313
8642
|
*
|
|
8314
8643
|
* **When to use**
|
|
@@ -9417,64 +9746,558 @@ function numberToJson(checks) {
|
|
|
9417
9746
|
* @since 4.0.0
|
|
9418
9747
|
*/
|
|
9419
9748
|
const number = /*#__PURE__*/ new Number$2();
|
|
9420
|
-
const resolveConcurrency = (value) => {
|
|
9421
|
-
value = value === "unbounded" ? Infinity : value ?? 1;
|
|
9422
|
-
return value > 1 ? { concurrency: value } : void 0;
|
|
9423
|
-
};
|
|
9424
9749
|
/**
|
|
9425
|
-
*
|
|
9426
|
-
*
|
|
9750
|
+
* AST node matching any `boolean` value (`true` or `false`).
|
|
9751
|
+
*
|
|
9752
|
+
* @see {@link boolean}
|
|
9753
|
+
* @see {@link isBoolean}
|
|
9754
|
+
*
|
|
9755
|
+
* @category models
|
|
9756
|
+
* @since 4.0.0
|
|
9427
9757
|
*/
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
|
|
9432
|
-
|
|
9433
|
-
}
|
|
9434
|
-
function getCandidateTypes(ast) {
|
|
9435
|
-
switch (ast._tag) {
|
|
9436
|
-
case "Null": return ["null"];
|
|
9437
|
-
case "Undefined": return ["undefined"];
|
|
9438
|
-
case "String":
|
|
9439
|
-
case "TemplateLiteral": return ["string"];
|
|
9440
|
-
case "Number": return ["number"];
|
|
9441
|
-
case "Boolean": return ["boolean"];
|
|
9442
|
-
case "Symbol":
|
|
9443
|
-
case "UniqueSymbol": return ["symbol"];
|
|
9444
|
-
case "BigInt": return ["bigint"];
|
|
9445
|
-
case "Arrays": return ["array"];
|
|
9446
|
-
case "ObjectKeyword": return [
|
|
9447
|
-
"object",
|
|
9448
|
-
"array",
|
|
9449
|
-
"function"
|
|
9450
|
-
];
|
|
9451
|
-
case "Objects": return ast.propertySignatures.length || ast.indexSignatures.length ? ["object"] : [
|
|
9452
|
-
"string",
|
|
9453
|
-
"number",
|
|
9454
|
-
"boolean",
|
|
9455
|
-
"symbol",
|
|
9456
|
-
"bigint",
|
|
9457
|
-
"object",
|
|
9458
|
-
"array",
|
|
9459
|
-
"function"
|
|
9460
|
-
];
|
|
9461
|
-
case "Enum": return Array.from(new Set(ast.enums.map(([, v]) => typeof v)));
|
|
9462
|
-
case "Literal": return [typeof ast.literal];
|
|
9463
|
-
case "Union": return Array.from(new Set(ast.types.flatMap(getCandidateTypes)));
|
|
9464
|
-
default: return [
|
|
9465
|
-
"null",
|
|
9466
|
-
"undefined",
|
|
9467
|
-
"string",
|
|
9468
|
-
"number",
|
|
9469
|
-
"boolean",
|
|
9470
|
-
"symbol",
|
|
9471
|
-
"bigint",
|
|
9472
|
-
"object",
|
|
9473
|
-
"array",
|
|
9474
|
-
"function"
|
|
9475
|
-
];
|
|
9758
|
+
var Boolean$1 = class extends Base {
|
|
9759
|
+
_tag = "Boolean";
|
|
9760
|
+
/** @internal */
|
|
9761
|
+
getParser() {
|
|
9762
|
+
return fromRefinement(this, isBoolean);
|
|
9476
9763
|
}
|
|
9477
|
-
|
|
9764
|
+
/** @internal */
|
|
9765
|
+
getExpected() {
|
|
9766
|
+
return "boolean";
|
|
9767
|
+
}
|
|
9768
|
+
};
|
|
9769
|
+
/**
|
|
9770
|
+
* Provides the singleton {@link Boolean} AST instance.
|
|
9771
|
+
*
|
|
9772
|
+
* **When to use**
|
|
9773
|
+
*
|
|
9774
|
+
* Use to reuse the standard AST node that accepts either `true` or `false` when
|
|
9775
|
+
* constructing schema ASTs directly.
|
|
9776
|
+
*
|
|
9777
|
+
* @see {@link Boolean} for the AST node class
|
|
9778
|
+
* @see {@link Literal} for exact boolean literal AST nodes
|
|
9779
|
+
*
|
|
9780
|
+
* @category constructors
|
|
9781
|
+
* @since 4.0.0
|
|
9782
|
+
*/
|
|
9783
|
+
const boolean = /*#__PURE__*/ new Boolean$1();
|
|
9784
|
+
/**
|
|
9785
|
+
* AST node for array-like types — both tuples and arrays.
|
|
9786
|
+
*
|
|
9787
|
+
* **When to use**
|
|
9788
|
+
*
|
|
9789
|
+
* Use when constructing or inspecting AST nodes for tuple or array-like schemas,
|
|
9790
|
+
* including rest elements.
|
|
9791
|
+
*
|
|
9792
|
+
* **Details**
|
|
9793
|
+
*
|
|
9794
|
+
* - `elements` — positional element types (tuple elements). An element is
|
|
9795
|
+
* optional if its {@link Context.isOptional} is `true`.
|
|
9796
|
+
* - `rest` — the rest/variadic element types. When non-empty, the first
|
|
9797
|
+
* entry is the "spread" type (e.g. `...Array<string>`), and subsequent
|
|
9798
|
+
* entries are trailing positional elements after the spread.
|
|
9799
|
+
* - `isMutable` — whether the resulting array is `readonly` (`false`) or
|
|
9800
|
+
* mutable (`true`).
|
|
9801
|
+
*
|
|
9802
|
+
* **Gotchas**
|
|
9803
|
+
*
|
|
9804
|
+
* Construction enforces TypeScript ordering rules: a required element
|
|
9805
|
+
* cannot follow an optional one, and an optional element cannot follow a
|
|
9806
|
+
* rest element.
|
|
9807
|
+
*
|
|
9808
|
+
* **Example** (Inspecting a tuple AST)
|
|
9809
|
+
*
|
|
9810
|
+
* ```ts
|
|
9811
|
+
* import { Schema, SchemaAST } from "effect"
|
|
9812
|
+
*
|
|
9813
|
+
* const schema = Schema.Tuple([Schema.String, Schema.Number])
|
|
9814
|
+
* const ast = schema.ast
|
|
9815
|
+
*
|
|
9816
|
+
* if (SchemaAST.isArrays(ast)) {
|
|
9817
|
+
* console.log(ast.elements.length) // 2
|
|
9818
|
+
* console.log(ast.rest.length) // 0
|
|
9819
|
+
* }
|
|
9820
|
+
* ```
|
|
9821
|
+
*
|
|
9822
|
+
* @see {@link isArrays}
|
|
9823
|
+
* @see {@link Objects}
|
|
9824
|
+
* @category models
|
|
9825
|
+
* @since 4.0.0
|
|
9826
|
+
*/
|
|
9827
|
+
var Arrays = class Arrays extends Base {
|
|
9828
|
+
_tag = "Arrays";
|
|
9829
|
+
isMutable;
|
|
9830
|
+
elements;
|
|
9831
|
+
rest;
|
|
9832
|
+
encodingChecks;
|
|
9833
|
+
constructor(isMutable, elements, rest, annotations, checks, encoding, context, encodingChecks) {
|
|
9834
|
+
super(annotations, checks, encoding, context);
|
|
9835
|
+
this.isMutable = isMutable;
|
|
9836
|
+
this.elements = elements;
|
|
9837
|
+
this.rest = rest;
|
|
9838
|
+
this.encodingChecks = encodingChecks;
|
|
9839
|
+
const i = elements.findIndex(isOptional);
|
|
9840
|
+
if (i !== -1 && (elements.slice(i + 1).some((e) => !isOptional(e)) || rest.length > 1)) throw new Error("A required element cannot follow an optional element. ts(1257)");
|
|
9841
|
+
if (rest.length > 1 && rest.slice(1).some(isOptional)) throw new Error("An optional element cannot follow a rest element. ts(1266)");
|
|
9842
|
+
}
|
|
9843
|
+
/** @internal */
|
|
9844
|
+
getParser(recur) {
|
|
9845
|
+
const ast = this;
|
|
9846
|
+
const elements = ast.elements.map((ast) => ({
|
|
9847
|
+
ast,
|
|
9848
|
+
parser: recur(ast)
|
|
9849
|
+
}));
|
|
9850
|
+
const rest = ast.rest.map((ast) => ({
|
|
9851
|
+
ast,
|
|
9852
|
+
parser: recur(ast)
|
|
9853
|
+
}));
|
|
9854
|
+
const elementLen = elements.length;
|
|
9855
|
+
const [head, ...tail] = rest;
|
|
9856
|
+
const tailLen = tail.length;
|
|
9857
|
+
function getParser(tailThreshold, index) {
|
|
9858
|
+
if (index < elementLen) return elements[index];
|
|
9859
|
+
else if (index >= tailThreshold) return tail[index - tailThreshold];
|
|
9860
|
+
return head;
|
|
9861
|
+
}
|
|
9862
|
+
return fnUntracedEager(function* (oinput, options) {
|
|
9863
|
+
if (oinput._tag === "None") return oinput;
|
|
9864
|
+
const input = oinput.value;
|
|
9865
|
+
if (!Array.isArray(input)) return yield* fail(new InvalidType(ast, oinput));
|
|
9866
|
+
const len = input.length;
|
|
9867
|
+
const state = {
|
|
9868
|
+
ast,
|
|
9869
|
+
getParser,
|
|
9870
|
+
oinput,
|
|
9871
|
+
len,
|
|
9872
|
+
tailThreshold: resolveTailThreshold(len, elementLen, tailLen),
|
|
9873
|
+
output: new globalThis.Array(len),
|
|
9874
|
+
issues: void 0,
|
|
9875
|
+
options
|
|
9876
|
+
};
|
|
9877
|
+
const concurrency = resolveConcurrency(options?.concurrency);
|
|
9878
|
+
const eff = parseArray(state, input, {
|
|
9879
|
+
concurrency: concurrency?.concurrency,
|
|
9880
|
+
end: ast.rest.length === 0 ? elementLen : Math.max(len, elementLen + tailLen)
|
|
9881
|
+
});
|
|
9882
|
+
if (eff) yield* eff;
|
|
9883
|
+
if (ast.rest.length === 0 && len > elementLen) for (let i = elementLen; i <= len - 1; i++) {
|
|
9884
|
+
const issue = new Pointer([i], new UnexpectedKey(ast, input[i]));
|
|
9885
|
+
if (options.errors === "all") if (state.issues) state.issues.push(issue);
|
|
9886
|
+
else state.issues = [issue];
|
|
9887
|
+
else return yield* fail(new Composite(ast, oinput, [issue]));
|
|
9888
|
+
}
|
|
9889
|
+
if (state.issues) return yield* fail(new Composite(ast, oinput, state.issues));
|
|
9890
|
+
return some(state.output);
|
|
9891
|
+
});
|
|
9892
|
+
}
|
|
9893
|
+
_rebuild(recur, checks, encodingChecks) {
|
|
9894
|
+
const elements = mapOrSame(this.elements, recur);
|
|
9895
|
+
const rest = mapOrSame(this.rest, recur);
|
|
9896
|
+
return elements === this.elements && rest === this.rest && checks === this.checks && encodingChecks === this.encodingChecks ? this : new Arrays(this.isMutable, elements, rest, this.annotations, checks, void 0, this.context, encodingChecks);
|
|
9897
|
+
}
|
|
9898
|
+
/** @internal */
|
|
9899
|
+
recur(recur) {
|
|
9900
|
+
return this._rebuild(recur, this.checks, this.encodingChecks);
|
|
9901
|
+
}
|
|
9902
|
+
/** @internal */
|
|
9903
|
+
flip(recur) {
|
|
9904
|
+
return this._rebuild(recur, this.encodingChecks, this.checks);
|
|
9905
|
+
}
|
|
9906
|
+
/** @internal */
|
|
9907
|
+
getExpected() {
|
|
9908
|
+
return "array";
|
|
9909
|
+
}
|
|
9910
|
+
};
|
|
9911
|
+
const parseArray = /*#__PURE__*/ iterateEager()({
|
|
9912
|
+
onItem(s, item, i) {
|
|
9913
|
+
const value = i < s.len ? some(item) : none();
|
|
9914
|
+
return s.getParser(s.tailThreshold, i).parser(value, s.options);
|
|
9915
|
+
},
|
|
9916
|
+
step(s, _, exit, i) {
|
|
9917
|
+
if (exit._tag === "Failure") return wrapPropertyKeyIssue(s, s.ast, i, exit);
|
|
9918
|
+
else if (exit.value._tag === "Some") s.output[i] = exit.value.value;
|
|
9919
|
+
else {
|
|
9920
|
+
const p = s.getParser(s.tailThreshold, i);
|
|
9921
|
+
if (isOptional(p.ast)) return;
|
|
9922
|
+
const issue = new Pointer([i], new MissingKey(p.ast.context?.annotations));
|
|
9923
|
+
if (s.options.errors === "all") if (s.issues) s.issues.push(issue);
|
|
9924
|
+
else s.issues = [issue];
|
|
9925
|
+
else return fail$1(new Composite(s.ast, s.oinput, [issue]));
|
|
9926
|
+
}
|
|
9927
|
+
}
|
|
9928
|
+
});
|
|
9929
|
+
function resolveTailThreshold(inputLen, elementLen, tailLen) {
|
|
9930
|
+
return Math.max(elementLen, inputLen - tailLen);
|
|
9931
|
+
}
|
|
9932
|
+
const resolveConcurrency = (value) => {
|
|
9933
|
+
value = value === "unbounded" ? Infinity : value ?? 1;
|
|
9934
|
+
return value > 1 ? { concurrency: value } : void 0;
|
|
9935
|
+
};
|
|
9936
|
+
const wrapPropertyKeyIssue = (s, ast, key, exit) => {
|
|
9937
|
+
if (exit.cause.reasons.length === 0) return exit;
|
|
9938
|
+
const issue = getSchemaIssue(exit.cause);
|
|
9939
|
+
if (issue === void 0) return failCause(map$1(exit.cause, (issue) => new Composite(ast, s.oinput, [new Pointer([key], issue)])));
|
|
9940
|
+
const pointer = new Pointer([key], issue);
|
|
9941
|
+
if (s.options.errors === "all") if (s.issues) s.issues.push(pointer);
|
|
9942
|
+
else s.issues = [pointer];
|
|
9943
|
+
else return fail$1(new Composite(ast, s.oinput, [pointer]));
|
|
9944
|
+
};
|
|
9945
|
+
/**
|
|
9946
|
+
* floating point or integer, with optional exponent
|
|
9947
|
+
* @internal
|
|
9948
|
+
*/
|
|
9949
|
+
const FINITE_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?";
|
|
9950
|
+
/**
|
|
9951
|
+
* Returns the object keys that match the index signature parameter schema.
|
|
9952
|
+
* @internal
|
|
9953
|
+
*/
|
|
9954
|
+
function getIndexSignatureKeys(input, parameter, options = defaultParseOptions) {
|
|
9955
|
+
let stringKeys;
|
|
9956
|
+
let symbolKeys;
|
|
9957
|
+
function go(parameter) {
|
|
9958
|
+
switch (parameter._tag) {
|
|
9959
|
+
case "String":
|
|
9960
|
+
case "TemplateLiteral": return (stringKeys ??= Object.keys(input)).filter((k) => parameter.matchPart(k, options) !== void 0);
|
|
9961
|
+
case "Number": return (stringKeys ??= Object.keys(input)).filter((k) => parameter.matchKey(k, options) !== void 0);
|
|
9962
|
+
case "Symbol": return (symbolKeys ??= Object.getOwnPropertySymbols(input)).filter((k) => parameter.matchKey(k, options) !== void 0);
|
|
9963
|
+
case "Union": return [...new Set(parameter.types.flatMap(go))];
|
|
9964
|
+
default: return [];
|
|
9965
|
+
}
|
|
9966
|
+
}
|
|
9967
|
+
return go(parameterFromPropertyKey(toEncoded(parameter)));
|
|
9968
|
+
}
|
|
9969
|
+
/**
|
|
9970
|
+
* Represents a named property within an {@link Objects} node.
|
|
9971
|
+
*
|
|
9972
|
+
* **Details**
|
|
9973
|
+
*
|
|
9974
|
+
* Pairs a `name` (any `PropertyKey`) with a `type` ({@link AST}). The
|
|
9975
|
+
* property's optionality and mutability are determined by the `type`'s
|
|
9976
|
+
* {@link Context}.
|
|
9977
|
+
*
|
|
9978
|
+
* @see {@link Objects}
|
|
9979
|
+
* @category models
|
|
9980
|
+
* @since 3.10.0
|
|
9981
|
+
*/
|
|
9982
|
+
var PropertySignature = class {
|
|
9983
|
+
name;
|
|
9984
|
+
type;
|
|
9985
|
+
constructor(name, type) {
|
|
9986
|
+
this.name = name;
|
|
9987
|
+
this.type = type;
|
|
9988
|
+
}
|
|
9989
|
+
};
|
|
9990
|
+
function isIndexSignatureParameterSide(ast) {
|
|
9991
|
+
switch (ast._tag) {
|
|
9992
|
+
case "String":
|
|
9993
|
+
case "Number":
|
|
9994
|
+
case "Symbol":
|
|
9995
|
+
case "TemplateLiteral": return true;
|
|
9996
|
+
case "Union": return ast.types.every(isIndexSignatureParameterSide);
|
|
9997
|
+
default: return false;
|
|
9998
|
+
}
|
|
9999
|
+
}
|
|
10000
|
+
function isIndexSignatureParameter(ast) {
|
|
10001
|
+
return isIndexSignatureParameterSide(ast) && isIndexSignatureParameterSide(toEncoded(ast));
|
|
10002
|
+
}
|
|
10003
|
+
/**
|
|
10004
|
+
* Represents an index signature entry within an {@link Objects} node.
|
|
10005
|
+
*
|
|
10006
|
+
* **When to use**
|
|
10007
|
+
*
|
|
10008
|
+
* Use when constructing or inspecting object AST entries for record-like keys
|
|
10009
|
+
* and values.
|
|
10010
|
+
*
|
|
10011
|
+
* **Details**
|
|
10012
|
+
*
|
|
10013
|
+
* - `parameter` — the key type AST (e.g. {@link String} for `string` keys,
|
|
10014
|
+
* {@link TemplateLiteral} for patterned keys).
|
|
10015
|
+
* - `type` — the value type SchemaAST.
|
|
10016
|
+
* - `merge` — optional {@link KeyValueCombiner} for handling duplicate keys.
|
|
10017
|
+
*
|
|
10018
|
+
* **Gotchas**
|
|
10019
|
+
*
|
|
10020
|
+
* Using `Schema.optionalKey` on the value type is not allowed for index
|
|
10021
|
+
* signatures (throws at construction); use `Schema.optional` instead.
|
|
10022
|
+
*
|
|
10023
|
+
* @see {@link Objects}
|
|
10024
|
+
* @see {@link PropertySignature}
|
|
10025
|
+
* @category models
|
|
10026
|
+
* @since 3.10.0
|
|
10027
|
+
*/
|
|
10028
|
+
var IndexSignature = class {
|
|
10029
|
+
parameter;
|
|
10030
|
+
type;
|
|
10031
|
+
merge;
|
|
10032
|
+
constructor(parameter, type, merge) {
|
|
10033
|
+
if (!isIndexSignatureParameter(parameter)) throw new Error(`Invalid index signature parameter ${parameter._tag}`);
|
|
10034
|
+
this.parameter = parameter;
|
|
10035
|
+
this.type = type;
|
|
10036
|
+
this.merge = merge;
|
|
10037
|
+
if (isOptional(type) && !containsUndefined(type)) throw new Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.");
|
|
10038
|
+
}
|
|
10039
|
+
};
|
|
10040
|
+
/**
|
|
10041
|
+
* AST node for object-like schemas, including structs and records.
|
|
10042
|
+
*
|
|
10043
|
+
* **When to use**
|
|
10044
|
+
*
|
|
10045
|
+
* Use when constructing or inspecting AST nodes for structs or records rather
|
|
10046
|
+
* than array-like schemas.
|
|
10047
|
+
*
|
|
10048
|
+
* **Details**
|
|
10049
|
+
*
|
|
10050
|
+
* - `propertySignatures` — named properties with their types (struct fields).
|
|
10051
|
+
* - `indexSignatures` — index signature entries (record patterns), each with
|
|
10052
|
+
* a `parameter` AST for matching keys and a `type` AST for values.
|
|
10053
|
+
*
|
|
10054
|
+
* An `Objects` node with no properties and no index signatures performs only a
|
|
10055
|
+
* non-nullish check: it accepts any value except `null` and `undefined`,
|
|
10056
|
+
* including primitive values.
|
|
10057
|
+
*
|
|
10058
|
+
* **Gotchas**
|
|
10059
|
+
*
|
|
10060
|
+
* Duplicate property names throw at construction time.
|
|
10061
|
+
*
|
|
10062
|
+
* **Example** (Inspecting a struct AST)
|
|
10063
|
+
*
|
|
10064
|
+
* ```ts
|
|
10065
|
+
* import { Schema, SchemaAST } from "effect"
|
|
10066
|
+
*
|
|
10067
|
+
* const schema = Schema.Struct({ name: Schema.String })
|
|
10068
|
+
* const ast = schema.ast
|
|
10069
|
+
*
|
|
10070
|
+
* if (SchemaAST.isObjects(ast)) {
|
|
10071
|
+
* for (const ps of ast.propertySignatures) {
|
|
10072
|
+
* console.log(ps.name, ps.type._tag)
|
|
10073
|
+
* }
|
|
10074
|
+
* // "name" "String"
|
|
10075
|
+
* }
|
|
10076
|
+
* ```
|
|
10077
|
+
*
|
|
10078
|
+
* @see {@link isObjects}
|
|
10079
|
+
* @see {@link PropertySignature}
|
|
10080
|
+
* @see {@link IndexSignature}
|
|
10081
|
+
* @see {@link Arrays}
|
|
10082
|
+
* @category models
|
|
10083
|
+
* @since 4.0.0
|
|
10084
|
+
*/
|
|
10085
|
+
var Objects = class Objects extends Base {
|
|
10086
|
+
_tag = "Objects";
|
|
10087
|
+
propertySignatures;
|
|
10088
|
+
indexSignatures;
|
|
10089
|
+
encodingChecks;
|
|
10090
|
+
constructor(propertySignatures, indexSignatures, annotations, checks, encoding, context, encodingChecks) {
|
|
10091
|
+
super(annotations, checks, encoding, context);
|
|
10092
|
+
this.propertySignatures = propertySignatures;
|
|
10093
|
+
this.indexSignatures = indexSignatures;
|
|
10094
|
+
this.encodingChecks = encodingChecks;
|
|
10095
|
+
const duplicates = propertySignatures.map((ps) => ps.name).filter((name, i, arr) => arr.indexOf(name) !== i);
|
|
10096
|
+
if (duplicates.length > 0) throw new Error(`Duplicate identifiers: ${JSON.stringify(duplicates)}. ts(2300)`);
|
|
10097
|
+
}
|
|
10098
|
+
/** @internal */
|
|
10099
|
+
getParser(recur) {
|
|
10100
|
+
const ast = this;
|
|
10101
|
+
const expectedKeys = [];
|
|
10102
|
+
const expectedKeysSet = /* @__PURE__ */ new Set();
|
|
10103
|
+
const properties = [];
|
|
10104
|
+
for (const ps of ast.propertySignatures) {
|
|
10105
|
+
expectedKeys.push(ps.name);
|
|
10106
|
+
expectedKeysSet.add(ps.name);
|
|
10107
|
+
properties.push({
|
|
10108
|
+
ps,
|
|
10109
|
+
parser: recur(ps.type),
|
|
10110
|
+
name: ps.name,
|
|
10111
|
+
type: ps.type
|
|
10112
|
+
});
|
|
10113
|
+
}
|
|
10114
|
+
const indexCount = ast.indexSignatures.length;
|
|
10115
|
+
if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) return fromRefinement(ast, isNotNullish);
|
|
10116
|
+
const parseIndexes = indexCount > 0 ? iterateEager()({
|
|
10117
|
+
onItem: fnUntracedEager(function* (s, [key, is]) {
|
|
10118
|
+
const effKey = recur(parameterFromPropertyKey(is.parameter))(some(key), s.options);
|
|
10119
|
+
const exitKey = effectIsExit(effKey) ? effKey : yield* exit$1(effKey);
|
|
10120
|
+
if (exitKey._tag === "Failure") {
|
|
10121
|
+
const eff = wrapPropertyKeyIssue(s, ast, key, exitKey);
|
|
10122
|
+
if (eff) yield* eff;
|
|
10123
|
+
return;
|
|
10124
|
+
}
|
|
10125
|
+
const value = some(s.input[key]);
|
|
10126
|
+
const effValue = recur(is.type)(value, s.options);
|
|
10127
|
+
const exitValue = effectIsExit(effValue) ? effValue : yield* exit$1(effValue);
|
|
10128
|
+
if (exitValue._tag === "Failure") {
|
|
10129
|
+
const eff = wrapPropertyKeyIssue(s, ast, key, exitValue);
|
|
10130
|
+
if (eff) yield* eff;
|
|
10131
|
+
return;
|
|
10132
|
+
} else if (exitKey.value._tag === "Some" && exitValue.value._tag === "Some") {
|
|
10133
|
+
const k2 = exitKey.value.value;
|
|
10134
|
+
if (expectedKeysSet.has(key) || expectedKeysSet.has(k2)) return;
|
|
10135
|
+
const v2 = exitValue.value.value;
|
|
10136
|
+
if (is.merge && is.merge.decode && Object.hasOwn(s.out, k2)) {
|
|
10137
|
+
const [k, v] = is.merge.decode.combine([k2, s.out[k2]], [k2, v2]);
|
|
10138
|
+
assignProperty(s.out, k, v);
|
|
10139
|
+
} else assignProperty(s.out, k2, v2);
|
|
10140
|
+
}
|
|
10141
|
+
}),
|
|
10142
|
+
step: (_s, _, exit) => exit._tag === "Failure" ? exit : void 0
|
|
10143
|
+
}) : void 0;
|
|
10144
|
+
return fnUntracedEager(function* (oinput, options) {
|
|
10145
|
+
if (oinput._tag === "None") return oinput;
|
|
10146
|
+
const input = oinput.value;
|
|
10147
|
+
if (!(typeof input === "object" && input !== null && !Array.isArray(input))) return yield* fail(new InvalidType(ast, oinput));
|
|
10148
|
+
const out = {};
|
|
10149
|
+
const state = {
|
|
10150
|
+
ast,
|
|
10151
|
+
oinput,
|
|
10152
|
+
input,
|
|
10153
|
+
out,
|
|
10154
|
+
issues: void 0,
|
|
10155
|
+
options
|
|
10156
|
+
};
|
|
10157
|
+
const errorsAllOption = options.errors === "all";
|
|
10158
|
+
const onExcessPropertyError = options.onExcessProperty === "error";
|
|
10159
|
+
const onExcessPropertyPreserve = options.onExcessProperty === "preserve";
|
|
10160
|
+
let inputKeys;
|
|
10161
|
+
if (ast.indexSignatures.length === 0 && (onExcessPropertyError || onExcessPropertyPreserve)) {
|
|
10162
|
+
inputKeys = Reflect.ownKeys(input);
|
|
10163
|
+
for (let i = 0; i < inputKeys.length; i++) {
|
|
10164
|
+
const key = inputKeys[i];
|
|
10165
|
+
if (!expectedKeysSet.has(key)) if (onExcessPropertyError) {
|
|
10166
|
+
const issue = new Pointer([key], new UnexpectedKey(ast, input[key]));
|
|
10167
|
+
if (errorsAllOption) {
|
|
10168
|
+
if (state.issues) state.issues.push(issue);
|
|
10169
|
+
else state.issues = [issue];
|
|
10170
|
+
continue;
|
|
10171
|
+
} else return yield* fail(new Composite(ast, oinput, [issue]));
|
|
10172
|
+
} else assignProperty(out, key, input[key]);
|
|
10173
|
+
}
|
|
10174
|
+
}
|
|
10175
|
+
const concurrency = resolveConcurrency(options?.concurrency);
|
|
10176
|
+
const eff = parseProperties(state, properties, concurrency);
|
|
10177
|
+
if (eff) yield* eff;
|
|
10178
|
+
if (parseIndexes) {
|
|
10179
|
+
const keyPairs = empty$1();
|
|
10180
|
+
for (let i = 0; i < indexCount; i++) {
|
|
10181
|
+
const is = ast.indexSignatures[i];
|
|
10182
|
+
const keys = getIndexSignatureKeys(input, is.parameter, options);
|
|
10183
|
+
for (let j = 0; j < keys.length; j++) {
|
|
10184
|
+
const key = keys[j];
|
|
10185
|
+
keyPairs.push([key, is]);
|
|
10186
|
+
}
|
|
10187
|
+
}
|
|
10188
|
+
const eff = parseIndexes(state, keyPairs, concurrency);
|
|
10189
|
+
if (eff) yield* eff;
|
|
10190
|
+
}
|
|
10191
|
+
if (state.issues) return yield* fail(new Composite(ast, oinput, state.issues));
|
|
10192
|
+
if (options.propertyOrder === "original") {
|
|
10193
|
+
const keys = (inputKeys ?? Reflect.ownKeys(input)).concat(expectedKeys);
|
|
10194
|
+
const preserved = {};
|
|
10195
|
+
for (const key of keys) if (Object.hasOwn(out, key)) assignProperty(preserved, key, out[key]);
|
|
10196
|
+
return some(preserved);
|
|
10197
|
+
}
|
|
10198
|
+
return some(out);
|
|
10199
|
+
});
|
|
10200
|
+
}
|
|
10201
|
+
_rebuild(recur, recurParameter, flipMerge, checks, encodingChecks) {
|
|
10202
|
+
const props = mapOrSame(this.propertySignatures, (ps) => {
|
|
10203
|
+
const t = recur(ps.type);
|
|
10204
|
+
return t === ps.type ? ps : new PropertySignature(ps.name, t);
|
|
10205
|
+
});
|
|
10206
|
+
const indexes = mapOrSame(this.indexSignatures, (is) => {
|
|
10207
|
+
const p = recurParameter(is.parameter);
|
|
10208
|
+
const t = recur(is.type);
|
|
10209
|
+
const merge = flipMerge ? is.merge?.flip() : is.merge;
|
|
10210
|
+
return p === is.parameter && t === is.type && merge === is.merge ? is : new IndexSignature(p, t, merge);
|
|
10211
|
+
});
|
|
10212
|
+
return props === this.propertySignatures && indexes === this.indexSignatures && checks === this.checks && encodingChecks === this.encodingChecks ? this : new Objects(props, indexes, this.annotations, checks, void 0, this.context, encodingChecks);
|
|
10213
|
+
}
|
|
10214
|
+
/** @internal */
|
|
10215
|
+
flip(recur) {
|
|
10216
|
+
return this._rebuild(recur, recur, true, this.encodingChecks, this.checks);
|
|
10217
|
+
}
|
|
10218
|
+
/** @internal */
|
|
10219
|
+
recur(recur, recurParameter = recur) {
|
|
10220
|
+
return this._rebuild(recur, recurParameter, false, this.checks, this.encodingChecks);
|
|
10221
|
+
}
|
|
10222
|
+
/** @internal */
|
|
10223
|
+
getExpected() {
|
|
10224
|
+
if (this.propertySignatures.length === 0 && this.indexSignatures.length === 0) return "object | array";
|
|
10225
|
+
return "object";
|
|
10226
|
+
}
|
|
10227
|
+
};
|
|
10228
|
+
const parseProperties = /*#__PURE__*/ iterateEager()({
|
|
10229
|
+
onItem(s, p) {
|
|
10230
|
+
const value = Object.hasOwn(s.input, p.name) ? some(s.input[p.name]) : none();
|
|
10231
|
+
return p.parser(value, s.options);
|
|
10232
|
+
},
|
|
10233
|
+
step(s, p, exit) {
|
|
10234
|
+
if (exit._tag === "Failure") return wrapPropertyKeyIssue(s, s.ast, p.name, exit);
|
|
10235
|
+
else if (exit.value._tag === "Some") assignProperty(s.out, p.name, exit.value.value);
|
|
10236
|
+
else if (!isOptional(p.type)) {
|
|
10237
|
+
const issue = new Pointer([p.name], new MissingKey(p.type.context?.annotations));
|
|
10238
|
+
if (s.options.errors === "all") {
|
|
10239
|
+
if (s.issues) s.issues.push(issue);
|
|
10240
|
+
else s.issues = [issue];
|
|
10241
|
+
return;
|
|
10242
|
+
} else return fail$1(new Composite(s.ast, s.oinput, [issue]));
|
|
10243
|
+
}
|
|
10244
|
+
}
|
|
10245
|
+
});
|
|
10246
|
+
function combineChecks(a, b) {
|
|
10247
|
+
if (!a) return b;
|
|
10248
|
+
if (!b) return a;
|
|
10249
|
+
return [...a, ...b];
|
|
10250
|
+
}
|
|
10251
|
+
/** @internal */
|
|
10252
|
+
function struct(fields, checks, annotations) {
|
|
10253
|
+
return new Objects(Reflect.ownKeys(fields).map((key) => {
|
|
10254
|
+
return new PropertySignature(key, fields[key].ast);
|
|
10255
|
+
}), [], annotations, checks);
|
|
10256
|
+
}
|
|
10257
|
+
function getCandidateTypes(ast) {
|
|
10258
|
+
switch (ast._tag) {
|
|
10259
|
+
case "Null": return ["null"];
|
|
10260
|
+
case "Undefined": return ["undefined"];
|
|
10261
|
+
case "String":
|
|
10262
|
+
case "TemplateLiteral": return ["string"];
|
|
10263
|
+
case "Number": return ["number"];
|
|
10264
|
+
case "Boolean": return ["boolean"];
|
|
10265
|
+
case "Symbol":
|
|
10266
|
+
case "UniqueSymbol": return ["symbol"];
|
|
10267
|
+
case "BigInt": return ["bigint"];
|
|
10268
|
+
case "Arrays": return ["array"];
|
|
10269
|
+
case "ObjectKeyword": return [
|
|
10270
|
+
"object",
|
|
10271
|
+
"array",
|
|
10272
|
+
"function"
|
|
10273
|
+
];
|
|
10274
|
+
case "Objects": return ast.propertySignatures.length || ast.indexSignatures.length ? ["object"] : [
|
|
10275
|
+
"string",
|
|
10276
|
+
"number",
|
|
10277
|
+
"boolean",
|
|
10278
|
+
"symbol",
|
|
10279
|
+
"bigint",
|
|
10280
|
+
"object",
|
|
10281
|
+
"array",
|
|
10282
|
+
"function"
|
|
10283
|
+
];
|
|
10284
|
+
case "Enum": return Array.from(new Set(ast.enums.map(([, v]) => typeof v)));
|
|
10285
|
+
case "Literal": return [typeof ast.literal];
|
|
10286
|
+
case "Union": return Array.from(new Set(ast.types.flatMap(getCandidateTypes)));
|
|
10287
|
+
default: return [
|
|
10288
|
+
"null",
|
|
10289
|
+
"undefined",
|
|
10290
|
+
"string",
|
|
10291
|
+
"number",
|
|
10292
|
+
"boolean",
|
|
10293
|
+
"symbol",
|
|
10294
|
+
"bigint",
|
|
10295
|
+
"object",
|
|
10296
|
+
"array",
|
|
10297
|
+
"function"
|
|
10298
|
+
];
|
|
10299
|
+
}
|
|
10300
|
+
}
|
|
9478
10301
|
/** @internal */
|
|
9479
10302
|
function collectSentinels(ast) {
|
|
9480
10303
|
switch (ast._tag) {
|
|
@@ -10074,6 +10897,14 @@ const flip = /*#__PURE__*/ memoize((ast) => {
|
|
|
10074
10897
|
const out = ast;
|
|
10075
10898
|
return out.flip?.(flip) ?? out.recur?.(flip) ?? out;
|
|
10076
10899
|
});
|
|
10900
|
+
/** @internal */
|
|
10901
|
+
function containsUndefined(ast) {
|
|
10902
|
+
switch (ast._tag) {
|
|
10903
|
+
case "Undefined": return true;
|
|
10904
|
+
case "Union": return ast.types.some(containsUndefined);
|
|
10905
|
+
default: return false;
|
|
10906
|
+
}
|
|
10907
|
+
}
|
|
10077
10908
|
function fromConst(ast, value) {
|
|
10078
10909
|
const succeed = succeedSome(value);
|
|
10079
10910
|
return (oinput) => {
|
|
@@ -10300,6 +11131,35 @@ function make$2(schema) {
|
|
|
10300
11131
|
throw new Error(issue.toString(), { cause: issue });
|
|
10301
11132
|
};
|
|
10302
11133
|
}
|
|
11134
|
+
/**
|
|
11135
|
+
* Creates an effectful decoder for `unknown` input.
|
|
11136
|
+
*
|
|
11137
|
+
* **When to use**
|
|
11138
|
+
*
|
|
11139
|
+
* Use when you need to decode untyped boundary input in an `Effect` whose
|
|
11140
|
+
* failure channel is `SchemaIssue.Issue`, while preserving transformations
|
|
11141
|
+
* and service requirements.
|
|
11142
|
+
*
|
|
11143
|
+
* **Details**
|
|
11144
|
+
*
|
|
11145
|
+
* The returned function succeeds with the schema's decoded `Type` or fails with a
|
|
11146
|
+
* `SchemaIssue.Issue`. Decoding service requirements are preserved in the returned
|
|
11147
|
+
* `Effect`. Parse options may be provided when creating the decoder and overridden
|
|
11148
|
+
* when applying it.
|
|
11149
|
+
*
|
|
11150
|
+
* @see {@link decodeEffect} for input already typed as the schema's `Encoded` type
|
|
11151
|
+
*
|
|
11152
|
+
* @category decoding
|
|
11153
|
+
* @since 4.0.0
|
|
11154
|
+
*/
|
|
11155
|
+
function decodeUnknownEffect$1(schema, options) {
|
|
11156
|
+
const parser = run$1(schema.ast);
|
|
11157
|
+
return options === void 0 ? parser : (input, overrideOptions) => parser(input, mergeParseOptions(options, overrideOptions));
|
|
11158
|
+
}
|
|
11159
|
+
const mergeParseOptions = (options, overrideOptions) => overrideOptions === void 0 ? options : {
|
|
11160
|
+
...options,
|
|
11161
|
+
...overrideOptions
|
|
11162
|
+
};
|
|
10303
11163
|
/** @internal */
|
|
10304
11164
|
function run$1(ast) {
|
|
10305
11165
|
const parser = recur(ast);
|
|
@@ -10406,6 +11266,72 @@ function make$1(ast, options) {
|
|
|
10406
11266
|
function fromIssueEffect(self) {
|
|
10407
11267
|
return catchCause(self, (cause) => failCauseSync(() => map$1(cause, (issue) => new SchemaError(issue))));
|
|
10408
11268
|
}
|
|
11269
|
+
//#endregion
|
|
11270
|
+
//#region node_modules/.pnpm/effect@4.0.0-beta.102/node_modules/effect/dist/Struct.js
|
|
11271
|
+
/**
|
|
11272
|
+
* Wraps a plain function as a {@link Lambda} value so it can be used with
|
|
11273
|
+
* {@link map}, {@link mapPick}, and {@link mapOmit}.
|
|
11274
|
+
*
|
|
11275
|
+
* **When to use**
|
|
11276
|
+
*
|
|
11277
|
+
* Use to create a typed lambda for struct mapping APIs that need type-level
|
|
11278
|
+
* input and output tracking.
|
|
11279
|
+
*
|
|
11280
|
+
* **Details**
|
|
11281
|
+
*
|
|
11282
|
+
* The type parameter `L` encodes both the input and output types at the type
|
|
11283
|
+
* level, allowing the compiler to track how struct value types change. At
|
|
11284
|
+
* runtime, the returned value is the same function; `lambda` only adjusts the
|
|
11285
|
+
* type.
|
|
11286
|
+
*
|
|
11287
|
+
* **Example** (Wrapping values in arrays)
|
|
11288
|
+
*
|
|
11289
|
+
* ```ts
|
|
11290
|
+
* import { pipe, Struct } from "effect"
|
|
11291
|
+
*
|
|
11292
|
+
* interface AsArray extends Struct.Lambda {
|
|
11293
|
+
* <A>(self: A): Array<A>
|
|
11294
|
+
* readonly "~lambda.out": Array<this["~lambda.in"]>
|
|
11295
|
+
* }
|
|
11296
|
+
*
|
|
11297
|
+
* const asArray = Struct.lambda<AsArray>((a) => [a])
|
|
11298
|
+
* const result = pipe({ x: 1, y: "hello" }, Struct.map(asArray))
|
|
11299
|
+
* console.log(result) // { x: [1], y: ["hello"] }
|
|
11300
|
+
* ```
|
|
11301
|
+
*
|
|
11302
|
+
* @see {@link Lambda} – the type-level interface
|
|
11303
|
+
* @see {@link map} – apply a lambda to all struct values
|
|
11304
|
+
* @category Lambda
|
|
11305
|
+
* @since 4.0.0
|
|
11306
|
+
*/
|
|
11307
|
+
const lambda = (f) => f;
|
|
11308
|
+
/**
|
|
11309
|
+
* Decodes an `unknown` input against a schema, returning an `Effect` that
|
|
11310
|
+
* succeeds with the decoded value or fails with a {@link SchemaError}.
|
|
11311
|
+
*
|
|
11312
|
+
* **When to use**
|
|
11313
|
+
*
|
|
11314
|
+
* Use when you need to decode unknown input in an `Effect` whose failure
|
|
11315
|
+
* channel is `SchemaError`.
|
|
11316
|
+
*
|
|
11317
|
+
* **Details**
|
|
11318
|
+
*
|
|
11319
|
+
* Prefer {@link decodeEffect} when the input is already typed as the schema's
|
|
11320
|
+
* `Encoded` type.
|
|
11321
|
+
* Options may be provided either when creating the decoder or when applying it;
|
|
11322
|
+
* application options override creation options.
|
|
11323
|
+
*
|
|
11324
|
+
* @see {@link SchemaParser.decodeUnknownEffect} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
11325
|
+
*
|
|
11326
|
+
* @category decoding
|
|
11327
|
+
* @since 4.0.0
|
|
11328
|
+
*/
|
|
11329
|
+
function decodeUnknownEffect(schema, options) {
|
|
11330
|
+
const parser = decodeUnknownEffect$1(schema, options);
|
|
11331
|
+
return (input, options) => {
|
|
11332
|
+
return fromIssueEffect(parser(input, options));
|
|
11333
|
+
};
|
|
11334
|
+
}
|
|
10409
11335
|
/**
|
|
10410
11336
|
* Creates a schema from an AST (Abstract Syntax Tree) node.
|
|
10411
11337
|
*
|
|
@@ -10432,6 +11358,69 @@ const make = make$1;
|
|
|
10432
11358
|
*/
|
|
10433
11359
|
const String$1 = /*#__PURE__*/ make(string);
|
|
10434
11360
|
/**
|
|
11361
|
+
* Schema for `boolean` values. Validates that the input is `typeof` `"boolean"`.
|
|
11362
|
+
*
|
|
11363
|
+
* **When to use**
|
|
11364
|
+
*
|
|
11365
|
+
* Use to validate values that are already JavaScript booleans.
|
|
11366
|
+
*
|
|
11367
|
+
* @see {@link BooleanFromBit} for a schema that decodes bit literals `0` or `1` into a boolean
|
|
11368
|
+
*
|
|
11369
|
+
* @category boolean
|
|
11370
|
+
* @since 4.0.0
|
|
11371
|
+
*/
|
|
11372
|
+
const Boolean = /*#__PURE__*/ make(boolean);
|
|
11373
|
+
function makeStruct(ast, fields) {
|
|
11374
|
+
return make(ast, {
|
|
11375
|
+
fields,
|
|
11376
|
+
mapFields(f, options) {
|
|
11377
|
+
const fields = f(this.fields);
|
|
11378
|
+
return makeStruct(struct(fields, options?.unsafePreserveChecks ? this.ast.checks : void 0), fields);
|
|
11379
|
+
}
|
|
11380
|
+
});
|
|
11381
|
+
}
|
|
11382
|
+
/**
|
|
11383
|
+
* Defines a struct schema from a map of field schemas.
|
|
11384
|
+
*
|
|
11385
|
+
* **Details**
|
|
11386
|
+
*
|
|
11387
|
+
* Each field value is a schema. Use {@link optionalKey} or {@link optional} to
|
|
11388
|
+
* mark fields as optional, and {@link mutableKey} to mark them as mutable.
|
|
11389
|
+
*
|
|
11390
|
+
* The resulting schema's `Type` is a readonly object type with the fields'
|
|
11391
|
+
* decoded types. The `Encoded` form mirrors the field schemas' encoded types.
|
|
11392
|
+
*
|
|
11393
|
+
* **Example** (Defining a basic struct)
|
|
11394
|
+
*
|
|
11395
|
+
* ```ts
|
|
11396
|
+
* import { Schema } from "effect"
|
|
11397
|
+
*
|
|
11398
|
+
* const Person = Schema.Struct({
|
|
11399
|
+
* name: Schema.String,
|
|
11400
|
+
* age: Schema.Number,
|
|
11401
|
+
* email: Schema.optionalKey(Schema.String)
|
|
11402
|
+
* })
|
|
11403
|
+
*
|
|
11404
|
+
* // { readonly name: string; readonly age: number; readonly email?: string }
|
|
11405
|
+
* type Person = typeof Person.Type
|
|
11406
|
+
*
|
|
11407
|
+
* const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
|
|
11408
|
+
* console.log(alice)
|
|
11409
|
+
* // { name: 'Alice', age: 30 }
|
|
11410
|
+
* ```
|
|
11411
|
+
*
|
|
11412
|
+
* @category constructors
|
|
11413
|
+
* @since 3.10.0
|
|
11414
|
+
*/
|
|
11415
|
+
function Struct(fields) {
|
|
11416
|
+
return makeStruct(struct(fields, void 0), fields);
|
|
11417
|
+
}
|
|
11418
|
+
/**
|
|
11419
|
+
* @category constructors
|
|
11420
|
+
* @since 4.0.0
|
|
11421
|
+
*/
|
|
11422
|
+
const ArraySchema = /*#__PURE__*/ lambda((schema) => make(new Arrays(false, [], [schema.ast]), { value: schema }));
|
|
11423
|
+
/**
|
|
10435
11424
|
* Adds a nominal brand to a schema, intersecting the output type with
|
|
10436
11425
|
* `Brand.Brand<B>` to prevent accidental mixing of structurally identical types.
|
|
10437
11426
|
*
|
|
@@ -12117,25 +13106,26 @@ const helpFor = (name) => {
|
|
|
12117
13106
|
].join("\n");
|
|
12118
13107
|
};
|
|
12119
13108
|
//#endregion
|
|
13109
|
+
//#region src/service/forge/error.ts
|
|
13110
|
+
var ForgeUnavailable = class extends TaggedError("ForgeUnavailable") {};
|
|
13111
|
+
//#endregion
|
|
12120
13112
|
//#region src/service/forge/service.ts
|
|
12121
|
-
var Forge = class extends Service()("Forge") {};
|
|
13113
|
+
var Forge = class extends Service()("adiff/Forge") {};
|
|
12122
13114
|
const LIMIT = "200";
|
|
12123
13115
|
const TIMEOUT_MS = 4e3;
|
|
13116
|
+
const FIELDS = "headRefName,state,isDraft";
|
|
13117
|
+
const decode = decodeUnknownEffect(ArraySchema(Struct({
|
|
13118
|
+
headRefName: String$1,
|
|
13119
|
+
state: String$1,
|
|
13120
|
+
isDraft: Boolean
|
|
13121
|
+
})));
|
|
12124
13122
|
const stateOf = (row) => {
|
|
12125
|
-
if (row.isDraft
|
|
13123
|
+
if (row.isDraft && row.state === "OPEN") return "draft";
|
|
12126
13124
|
if (row.state === "MERGED") return "merged";
|
|
12127
13125
|
if (row.state === "CLOSED") return "closed";
|
|
12128
13126
|
return "open";
|
|
12129
13127
|
};
|
|
12130
|
-
const
|
|
12131
|
-
const rows = JSON.parse(raw);
|
|
12132
|
-
if (!Array.isArray(rows)) return [];
|
|
12133
|
-
return rows.filter((row) => typeof row.headRefName === "string").map((row) => ({
|
|
12134
|
-
branch: String(row.headRefName),
|
|
12135
|
-
state: stateOf(row)
|
|
12136
|
-
}));
|
|
12137
|
-
};
|
|
12138
|
-
const ask = (repo) => new Promise((resolve) => {
|
|
13128
|
+
const ask = (repo) => callback((resume) => {
|
|
12139
13129
|
execFile("gh", [
|
|
12140
13130
|
"pr",
|
|
12141
13131
|
"list",
|
|
@@ -12144,21 +13134,40 @@ const ask = (repo) => new Promise((resolve) => {
|
|
|
12144
13134
|
"--limit",
|
|
12145
13135
|
LIMIT,
|
|
12146
13136
|
"--json",
|
|
12147
|
-
|
|
13137
|
+
FIELDS
|
|
12148
13138
|
], {
|
|
12149
13139
|
cwd: repo,
|
|
12150
13140
|
timeout: TIMEOUT_MS,
|
|
12151
13141
|
encoding: "utf8"
|
|
12152
13142
|
}, (error, stdout) => {
|
|
12153
|
-
if (error
|
|
12154
|
-
|
|
12155
|
-
|
|
12156
|
-
|
|
12157
|
-
|
|
12158
|
-
|
|
13143
|
+
if (error === null) return resume(succeed(stdout));
|
|
13144
|
+
resume(fail(new ForgeUnavailable({
|
|
13145
|
+
repo,
|
|
13146
|
+
reason: error.message
|
|
13147
|
+
})));
|
|
13148
|
+
});
|
|
13149
|
+
});
|
|
13150
|
+
const read = fn("Forge.read")(function* (repo, raw) {
|
|
13151
|
+
const parsed = yield* try_({
|
|
13152
|
+
try: () => JSON.parse(raw),
|
|
13153
|
+
catch: (cause) => new ForgeUnavailable({
|
|
13154
|
+
repo,
|
|
13155
|
+
reason: String(cause)
|
|
13156
|
+
})
|
|
12159
13157
|
});
|
|
13158
|
+
return (yield* mapError(decode(parsed), (cause) => new ForgeUnavailable({
|
|
13159
|
+
repo,
|
|
13160
|
+
reason: String(cause)
|
|
13161
|
+
}))).map((row) => ({
|
|
13162
|
+
branch: row.headRefName,
|
|
13163
|
+
state: stateOf(row)
|
|
13164
|
+
}));
|
|
13165
|
+
});
|
|
13166
|
+
const pulls = fn("Forge.pulls")(function* (repo) {
|
|
13167
|
+
const raw = yield* ask(repo);
|
|
13168
|
+
return yield* read(repo, raw);
|
|
12160
13169
|
});
|
|
12161
|
-
const ForgeLive = succeed$1(Forge)({ pulls
|
|
13170
|
+
const ForgeLive = succeed$1(Forge)({ pulls });
|
|
12162
13171
|
//#endregion
|
|
12163
13172
|
//#region src/tui/gaps.ts
|
|
12164
13173
|
const sourceLength = (source) => source.at(-1)?.trim() === "" ? source.length - 1 : source.length;
|
|
@@ -12429,6 +13438,8 @@ const initialState = (branches) => ({
|
|
|
12429
13438
|
patches: [],
|
|
12430
13439
|
patchIndex: 0,
|
|
12431
13440
|
cursor: 0,
|
|
13441
|
+
stop: 0,
|
|
13442
|
+
opened: [],
|
|
12432
13443
|
anchorRow: 0,
|
|
12433
13444
|
selecting: false,
|
|
12434
13445
|
draft: "",
|
|
@@ -12679,6 +13690,14 @@ const commentRowsIn = (state, fileIndex) => {
|
|
|
12679
13690
|
const notes = [...state.pending, ...state.sent].filter((entry) => entry.file === patch.path);
|
|
12680
13691
|
return patch.rows.filter((row) => notes.some((note) => lineOnSide(row, note.side) === note.end)).map((row) => row.index).toSorted((left, right) => left - right);
|
|
12681
13692
|
};
|
|
13693
|
+
const threadsAtRow = (state, row) => {
|
|
13694
|
+
const patch = selectedPatch(state);
|
|
13695
|
+
const here = patch?.rows[row];
|
|
13696
|
+
if (patch === void 0 || here === void 0) return [];
|
|
13697
|
+
return state.sent.filter((entry) => entry.file === patch.path && entry.id !== void 0 && lineOnSide(here, entry.side) === entry.end);
|
|
13698
|
+
};
|
|
13699
|
+
const stopsAtRow = (state, row) => 1 + threadsAtRow(state, row).length;
|
|
13700
|
+
const threadAtStop = (state) => state.stop === 0 ? void 0 : threadsAtRow(state, state.cursor)[state.stop - 1];
|
|
12682
13701
|
const threadAtRow = (state, row) => {
|
|
12683
13702
|
const patch = selectedPatch(state);
|
|
12684
13703
|
const here = patch?.rows[row];
|
|
@@ -13019,14 +14038,14 @@ const commands = [
|
|
|
13019
14038
|
}),
|
|
13020
14039
|
command({
|
|
13021
14040
|
action: "tree.collapse",
|
|
13022
|
-
title: "Close the folder, layer, or
|
|
14041
|
+
title: "Close the folder, layer, gap, or settled thread",
|
|
13023
14042
|
category: "Files",
|
|
13024
14043
|
keys: ["h"],
|
|
13025
14044
|
screens: ["review"]
|
|
13026
14045
|
}),
|
|
13027
14046
|
command({
|
|
13028
14047
|
action: "tree.expand",
|
|
13029
|
-
title: "Open the folder, layer, or
|
|
14048
|
+
title: "Open the folder, layer, gap, or settled thread",
|
|
13030
14049
|
category: "Files",
|
|
13031
14050
|
keys: ["l"],
|
|
13032
14051
|
screens: ["review"]
|
|
@@ -13255,8 +14274,31 @@ const withCursorVisible = (state) => {
|
|
|
13255
14274
|
};
|
|
13256
14275
|
const moveCursor = (state, delta) => withCursorVisible({
|
|
13257
14276
|
...state,
|
|
14277
|
+
stop: 0,
|
|
13258
14278
|
cursor: clamp(state.cursor + delta, 0, lastRow(selectedPatch(state)))
|
|
13259
14279
|
});
|
|
14280
|
+
const stepStop = (state, delta) => {
|
|
14281
|
+
const here = stopsAtRow(state, state.cursor) - 1;
|
|
14282
|
+
if (delta > 0 && state.stop < here) return {
|
|
14283
|
+
...state,
|
|
14284
|
+
stop: state.stop + 1
|
|
14285
|
+
};
|
|
14286
|
+
if (delta < 0 && state.stop > 0) return {
|
|
14287
|
+
...state,
|
|
14288
|
+
stop: state.stop - 1
|
|
14289
|
+
};
|
|
14290
|
+
const row = clamp(state.cursor + delta, 0, lastRow(selectedPatch(state)));
|
|
14291
|
+
if (row === state.cursor) return state;
|
|
14292
|
+
const landing = delta < 0 ? stopsAtRow({
|
|
14293
|
+
...state,
|
|
14294
|
+
cursor: row
|
|
14295
|
+
}, row) - 1 : 0;
|
|
14296
|
+
return withCursorVisible({
|
|
14297
|
+
...state,
|
|
14298
|
+
cursor: row,
|
|
14299
|
+
stop: landing
|
|
14300
|
+
});
|
|
14301
|
+
};
|
|
13260
14302
|
const scrolled = (state, delta) => {
|
|
13261
14303
|
const highest = Math.max(0, rowsIn(state) - Math.max(1, state.viewport));
|
|
13262
14304
|
return {
|
|
@@ -13272,6 +14314,7 @@ const draggedTo = (state, from, to) => ({
|
|
|
13272
14314
|
});
|
|
13273
14315
|
const atRow = (state, row) => withCursorVisible({
|
|
13274
14316
|
...state,
|
|
14317
|
+
stop: 0,
|
|
13275
14318
|
cursor: clamp(row, 0, lastRow(selectedPatch(state)))
|
|
13276
14319
|
});
|
|
13277
14320
|
const layerHunk = (state, delta) => {
|
|
@@ -13338,7 +14381,7 @@ const moveLayer = (state, delta) => {
|
|
|
13338
14381
|
};
|
|
13339
14382
|
};
|
|
13340
14383
|
const inRail = (state, delta) => onLayers(state) ? moveLayer(state, delta) : moveFile(state, delta);
|
|
13341
|
-
const layerDown = (state, delta) => state.focus === "tree" ? inRail(state, delta) :
|
|
14384
|
+
const layerDown = (state, delta) => state.focus === "tree" ? inRail(state, delta) : stepStop(state, delta);
|
|
13342
14385
|
const toggleRail = (state) => {
|
|
13343
14386
|
if (state.layers.length === 0) return withNotice(state, "no layers for this branch");
|
|
13344
14387
|
if (state.rail === "layers") return {
|
|
@@ -13367,7 +14410,18 @@ const foldLayer = (state, shut) => {
|
|
|
13367
14410
|
openLayers: shut ? open : [...open, state.layerIndex]
|
|
13368
14411
|
};
|
|
13369
14412
|
};
|
|
13370
|
-
const
|
|
14413
|
+
const foldThread = (state, shut, id) => {
|
|
14414
|
+
const rest = state.opened.filter((held) => held !== id);
|
|
14415
|
+
return {
|
|
14416
|
+
...state,
|
|
14417
|
+
opened: shut ? rest : [...rest, id]
|
|
14418
|
+
};
|
|
14419
|
+
};
|
|
14420
|
+
const fold = (state, shut) => {
|
|
14421
|
+
const thread = threadAtStop(state);
|
|
14422
|
+
if (thread?.id !== void 0 && thread.settled === true) return foldThread(state, shut, thread.id);
|
|
14423
|
+
return onLayers(state) ? foldLayer(state, shut) : foldDirectory(state, shut);
|
|
14424
|
+
};
|
|
13371
14425
|
const moveBranch = (state, delta) => ({
|
|
13372
14426
|
...state,
|
|
13373
14427
|
branchIndex: clamp(state.branchIndex + delta, 0, Math.max(0, state.branches.length - 1))
|
|
@@ -14091,6 +15145,15 @@ var DiffView = class {
|
|
|
14091
15145
|
const at = Math.max(0, Math.min(this.display.length - 1, line));
|
|
14092
15146
|
return this.display[at]?.row ?? 0;
|
|
14093
15147
|
}
|
|
15148
|
+
stopAt(visual) {
|
|
15149
|
+
return this.display[this.lineAt(visual)]?.stop ?? 0;
|
|
15150
|
+
}
|
|
15151
|
+
carries(visual) {
|
|
15152
|
+
const entry = this.display[this.lineAt(visual)];
|
|
15153
|
+
if (entry === void 0) return false;
|
|
15154
|
+
if (entry.prose) return false;
|
|
15155
|
+
return true;
|
|
15156
|
+
}
|
|
14094
15157
|
isComment(visual) {
|
|
14095
15158
|
const entry = this.display[this.lineAt(visual)];
|
|
14096
15159
|
return entry?.comment === true || entry?.prose === true;
|
|
@@ -14134,7 +15197,7 @@ const startsOf = (display) => {
|
|
|
14134
15197
|
const bareOf = (display) => new Set(display.flatMap((entry, index) => entry.comment || entry.gap || entry.prose ? [index] : []));
|
|
14135
15198
|
const keyOf = (room, notes, prose) => [
|
|
14136
15199
|
room,
|
|
14137
|
-
...notes.map((note) => `${note.side}${note.line}:${note.body}`),
|
|
15200
|
+
...notes.map((note) => `${note.side}${note.line}:${note.folded ? "-" : "+"}${note.body}`),
|
|
14138
15201
|
...prose.map((entry) => `p${entry.line}${entry.after ? ">" : "<"}:${entry.markdown}`)
|
|
14139
15202
|
].join("\0");
|
|
14140
15203
|
const groupOf = (entry) => {
|
|
@@ -14189,14 +15252,15 @@ const spokenLines = (body, room) => {
|
|
|
14189
15252
|
return wrap(body.replaceAll("\n", " "), Math.max(NOTE_MIN, room - 2)).map((text, at) => at === 0 ? `${ANSWER_MARK} ${text}` : ` ${text}`);
|
|
14190
15253
|
};
|
|
14191
15254
|
const answerLines = (note, room) => note.answers.flatMap((body) => spokenLines(body, room));
|
|
14192
|
-
const noteLines = (note, room) => [
|
|
15255
|
+
const noteLines = (note, room) => note.folded ? [`${headOf(note)} · press l`] : [
|
|
14193
15256
|
headOf(note),
|
|
14194
15257
|
...note.body.split("\n").flatMap((line) => wrap(line, room)),
|
|
14195
15258
|
...answerLines(note, room)
|
|
14196
15259
|
];
|
|
14197
|
-
const noteRows = (note, row, room) => noteLines(note, room).map((line, index) => ({
|
|
15260
|
+
const noteRows = (note, row, room, stop) => noteLines(note, room).map((line, index) => ({
|
|
14198
15261
|
text: `${marks().rule} ${line}`,
|
|
14199
15262
|
row,
|
|
15263
|
+
stop,
|
|
14200
15264
|
comment: true,
|
|
14201
15265
|
sent: note.sent,
|
|
14202
15266
|
label: index === 0,
|
|
@@ -14206,6 +15270,7 @@ const noteRows = (note, row, room) => noteLines(note, room).map((line, index) =>
|
|
|
14206
15270
|
const proseRows = (entry, row, room) => [...entry.markdown.split("\n").flatMap((line) => wrap(line, room - 2)), ""].map((line) => ({
|
|
14207
15271
|
text: line.length === 0 ? "" : ` ${line}`,
|
|
14208
15272
|
row,
|
|
15273
|
+
stop: 0,
|
|
14209
15274
|
comment: false,
|
|
14210
15275
|
sent: false,
|
|
14211
15276
|
label: false,
|
|
@@ -14217,10 +15282,11 @@ const proseAt = (plan, row, after) => {
|
|
|
14217
15282
|
if (line === void 0) return [];
|
|
14218
15283
|
return plan.prose.filter((entry) => entry.after === after && entry.line === line);
|
|
14219
15284
|
};
|
|
14220
|
-
const notesAt = (plan, row) => plan.notes.filter((note) => sideLineOf(row, note.side) === note.line).flatMap((note) => noteRows(note, row.index, plan.room));
|
|
15285
|
+
const notesAt = (plan, row) => plan.notes.filter((note) => sideLineOf(row, note.side) === note.line).flatMap((note, at) => noteRows(note, row.index, plan.room, at + 1));
|
|
14221
15286
|
const codeRow = (plan, row) => ({
|
|
14222
15287
|
text: row.text,
|
|
14223
15288
|
row: row.index,
|
|
15289
|
+
stop: 0,
|
|
14224
15290
|
comment: false,
|
|
14225
15291
|
sent: false,
|
|
14226
15292
|
label: false,
|
|
@@ -14558,7 +15624,10 @@ const waitingLabel = (branch) => {
|
|
|
14558
15624
|
if (branch.staged > 0) return `${branch.staged} staged`;
|
|
14559
15625
|
return branch.unread > 0 ? `${branch.unread} unread` : "";
|
|
14560
15626
|
};
|
|
14561
|
-
const
|
|
15627
|
+
const inRange = (state, row, from, to) => state.selecting && row >= from && row <= to;
|
|
15628
|
+
const notesOf = (comments, path, sent, opened = []) => comments.filter((entry) => entry.file === path).map((entry) => ({
|
|
15629
|
+
id: entry.id ?? "",
|
|
15630
|
+
folded: entry.settled === true && !(entry.id !== void 0 && opened.includes(entry.id)),
|
|
14562
15631
|
side: entry.side,
|
|
14563
15632
|
line: entry.end,
|
|
14564
15633
|
body: entry.body,
|
|
@@ -14568,7 +15637,7 @@ const notesOf = (comments, path, sent) => comments.filter((entry) => entry.file
|
|
|
14568
15637
|
asks: entry.asks === true,
|
|
14569
15638
|
answers: entry.answers ?? []
|
|
14570
15639
|
}));
|
|
14571
|
-
const notesFor = (state, path) => [...notesOf(state.sent, path, true), ...notesOf(state.pending, path, false)];
|
|
15640
|
+
const notesFor = (state, path) => [...notesOf(state.sent, path, true, state.opened), ...notesOf(state.pending, path, false)];
|
|
14572
15641
|
const paired = (chunks) => {
|
|
14573
15642
|
const chips = [];
|
|
14574
15643
|
for (let at = 0; at < chunks.length; at += CHIP_CHUNKS) chips.push(chunks.slice(at, at + CHIP_CHUNKS));
|
|
@@ -15059,12 +16128,15 @@ var Screen = class {
|
|
|
15059
16128
|
const [from, to] = selectionRange(state);
|
|
15060
16129
|
const marked = markedRows(state);
|
|
15061
16130
|
const drawn = this.view.drawn();
|
|
15062
|
-
const bare = (visual) => visual >= drawn || this.view.
|
|
15063
|
-
const
|
|
15064
|
-
|
|
15065
|
-
const
|
|
15066
|
-
|
|
15067
|
-
|
|
16131
|
+
const bare = (visual) => visual >= drawn || !this.view.carries(visual) || this.view.isRunOn(visual);
|
|
16132
|
+
const held = (visual) => {
|
|
16133
|
+
const row = this.view.rowAt(visual);
|
|
16134
|
+
const onCode = this.view.stopAt(visual) === 0;
|
|
16135
|
+
const standing = row === state.cursor && this.view.stopAt(visual) === state.stop;
|
|
16136
|
+
const within = onCode && inRange(state, row, from, to);
|
|
16137
|
+
return `${standing || within ? marks().cursor : " "}${onCode && marked.has(row) ? marks().comment : " "}`;
|
|
16138
|
+
};
|
|
16139
|
+
const rows = Array.from({ length: height }, (_, index) => bare(top + index) ? " " : held(top + index));
|
|
15068
16140
|
this.gutter.content = rows.join("\n");
|
|
15069
16141
|
}
|
|
15070
16142
|
paintSticky(state, top) {
|
|
@@ -15409,11 +16481,15 @@ var App = class {
|
|
|
15409
16481
|
}
|
|
15410
16482
|
async settleHere() {
|
|
15411
16483
|
const branch = selectedBranch(this.state);
|
|
15412
|
-
const id = threadAtRow(this.state, this.state.cursor)?.id;
|
|
16484
|
+
const id = (threadAtStop(this.state) ?? threadAtRow(this.state, this.state.cursor))?.id;
|
|
15413
16485
|
if (branch === void 0 || id === void 0) return this.commit(withNotice(this.state, "no thread here"));
|
|
15414
16486
|
await this.run(settleThread(this.repo, branch.branch, id, (/* @__PURE__ */ new Date()).toISOString()));
|
|
15415
16487
|
const sent = await this.loadSent(branch.branch);
|
|
15416
|
-
|
|
16488
|
+
const held = withSent({
|
|
16489
|
+
...this.state,
|
|
16490
|
+
opened: this.state.opened.filter((was) => was !== id)
|
|
16491
|
+
}, sent);
|
|
16492
|
+
this.commit(withNotice(held, "settled"));
|
|
15417
16493
|
}
|
|
15418
16494
|
async reloadList() {
|
|
15419
16495
|
const here = selectedBranch(this.state)?.branch;
|
|
@@ -15522,8 +16598,8 @@ var App = class {
|
|
|
15522
16598
|
return this.run(listSent(this.repo, branch));
|
|
15523
16599
|
}
|
|
15524
16600
|
async loadPulls() {
|
|
15525
|
-
const
|
|
15526
|
-
const pulls = await this.run(
|
|
16601
|
+
const asked = (await this.run(map(Forge, (service) => service))).pulls(this.repo);
|
|
16602
|
+
const pulls = await this.run(asked.pipe(catchTag("ForgeUnavailable", () => succeed([]))));
|
|
15527
16603
|
if (pulls.length === 0) return;
|
|
15528
16604
|
const found = Object.fromEntries(pulls.map((pull) => [pull.branch, pull.state]));
|
|
15529
16605
|
this.commit(withPulls(this.state, found));
|