effect 3.13.2 → 3.13.4
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/dist/cjs/FiberHandle.js +5 -3
- package/dist/cjs/FiberHandle.js.map +1 -1
- package/dist/cjs/FiberMap.js +5 -3
- package/dist/cjs/FiberMap.js.map +1 -1
- package/dist/cjs/FiberSet.js +6 -3
- package/dist/cjs/FiberSet.js.map +1 -1
- package/dist/cjs/JSONSchema.js +7 -7
- package/dist/cjs/JSONSchema.js.map +1 -1
- package/dist/cjs/Option.js +3 -15
- package/dist/cjs/Option.js.map +1 -1
- package/dist/cjs/ParseResult.js +1 -1
- package/dist/cjs/ParseResult.js.map +1 -1
- package/dist/cjs/Schema.js +593 -522
- package/dist/cjs/Schema.js.map +1 -1
- package/dist/cjs/TRef.js.map +1 -1
- package/dist/cjs/internal/fiberRuntime.js +4 -5
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/stm/core.js +5 -5
- package/dist/cjs/internal/stm/core.js.map +1 -1
- package/dist/cjs/internal/stm/entry.js.map +1 -0
- package/dist/cjs/internal/stm/journal.js.map +1 -0
- package/dist/cjs/internal/stm/stm.js +2 -2
- package/dist/cjs/internal/stm/stm.js.map +1 -1
- package/dist/cjs/internal/stm/{stm/stmState.js → stmState.js} +7 -7
- package/dist/cjs/internal/stm/stmState.js.map +1 -0
- package/dist/cjs/internal/stm/{stm/tExit.js → tExit.js} +5 -5
- package/dist/cjs/internal/stm/tExit.js.map +1 -0
- package/dist/cjs/internal/stm/tMap.js.map +1 -1
- package/dist/cjs/internal/stm/tRef.js +2 -2
- package/dist/cjs/internal/stm/tRef.js.map +1 -1
- package/dist/cjs/internal/stm/{stm/tryCommit.js → tryCommit.js} +1 -1
- package/dist/cjs/internal/stm/tryCommit.js.map +1 -0
- package/dist/cjs/internal/stm/txnId.js.map +1 -0
- package/dist/cjs/internal/stm/versioned.js.map +1 -0
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Array.d.ts +6 -6
- package/dist/dts/Array.d.ts.map +1 -1
- package/dist/dts/Context.d.ts +1 -1
- package/dist/dts/Context.d.ts.map +1 -1
- package/dist/dts/FiberHandle.d.ts.map +1 -1
- package/dist/dts/FiberMap.d.ts.map +1 -1
- package/dist/dts/FiberSet.d.ts.map +1 -1
- package/dist/dts/Option.d.ts +3 -42
- package/dist/dts/Option.d.ts.map +1 -1
- package/dist/dts/ParseResult.d.ts.map +1 -1
- package/dist/dts/Schema.d.ts +400 -270
- package/dist/dts/Schema.d.ts.map +1 -1
- package/dist/dts/internal/stm/entry.d.ts.map +1 -0
- package/dist/dts/internal/stm/journal.d.ts.map +1 -0
- package/dist/dts/internal/stm/stmState.d.ts.map +1 -0
- package/dist/dts/internal/stm/tExit.d.ts.map +1 -0
- package/dist/dts/internal/stm/tryCommit.d.ts.map +1 -0
- package/dist/dts/internal/stm/txnId.d.ts.map +1 -0
- package/dist/dts/internal/stm/versioned.d.ts.map +1 -0
- package/dist/esm/FiberHandle.js +5 -3
- package/dist/esm/FiberHandle.js.map +1 -1
- package/dist/esm/FiberMap.js +5 -3
- package/dist/esm/FiberMap.js.map +1 -1
- package/dist/esm/FiberSet.js +6 -3
- package/dist/esm/FiberSet.js.map +1 -1
- package/dist/esm/JSONSchema.js +7 -7
- package/dist/esm/JSONSchema.js.map +1 -1
- package/dist/esm/Option.js +3 -15
- package/dist/esm/Option.js.map +1 -1
- package/dist/esm/ParseResult.js +1 -1
- package/dist/esm/ParseResult.js.map +1 -1
- package/dist/esm/Schema.js +538 -490
- package/dist/esm/Schema.js.map +1 -1
- package/dist/esm/TRef.js.map +1 -1
- package/dist/esm/internal/fiberRuntime.js +4 -5
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/stm/core.js +5 -5
- package/dist/esm/internal/stm/core.js.map +1 -1
- package/dist/esm/internal/stm/entry.js.map +1 -0
- package/dist/esm/internal/stm/journal.js.map +1 -0
- package/dist/esm/internal/stm/stm.js +2 -2
- package/dist/esm/internal/stm/stm.js.map +1 -1
- package/dist/esm/internal/stm/{stm/stmState.js → stmState.js} +7 -7
- package/dist/esm/internal/stm/stmState.js.map +1 -0
- package/dist/esm/internal/stm/{stm/tExit.js → tExit.js} +5 -5
- package/dist/esm/internal/stm/tExit.js.map +1 -0
- package/dist/esm/internal/stm/tMap.js.map +1 -1
- package/dist/esm/internal/stm/tRef.js +2 -2
- package/dist/esm/internal/stm/tRef.js.map +1 -1
- package/dist/esm/internal/stm/{stm/tryCommit.js → tryCommit.js} +1 -1
- package/dist/esm/internal/stm/tryCommit.js.map +1 -0
- package/dist/esm/internal/stm/txnId.js.map +1 -0
- package/dist/esm/internal/stm/versioned.js.map +1 -0
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Array.ts +6 -6
- package/src/Context.ts +1 -1
- package/src/FiberHandle.ts +11 -7
- package/src/FiberMap.ts +11 -7
- package/src/FiberSet.ts +9 -7
- package/src/JSONSchema.ts +7 -7
- package/src/Option.ts +7 -46
- package/src/ParseResult.ts +1 -3
- package/src/Schema.ts +1337 -1137
- package/src/TRef.ts +3 -3
- package/src/internal/fiberRuntime.ts +5 -4
- package/src/internal/stm/core.ts +5 -5
- package/src/internal/stm/{stm/entry.ts → entry.ts} +1 -1
- package/src/internal/stm/{stm/journal.ts → journal.ts} +1 -1
- package/src/internal/stm/stm.ts +2 -2
- package/src/internal/stm/{stm/stmState.ts → stmState.ts} +7 -7
- package/src/internal/stm/{stm/tExit.ts → tExit.ts} +7 -7
- package/src/internal/stm/tMap.ts +1 -1
- package/src/internal/stm/tRef.ts +4 -4
- package/src/internal/stm/{stm/tryCommit.ts → tryCommit.ts} +2 -2
- package/src/internal/version.ts +1 -1
- package/dist/cjs/internal/stm/stm/entry.js.map +0 -1
- package/dist/cjs/internal/stm/stm/journal.js.map +0 -1
- package/dist/cjs/internal/stm/stm/opCodes/stm.js +0 -31
- package/dist/cjs/internal/stm/stm/opCodes/stm.js.map +0 -1
- package/dist/cjs/internal/stm/stm/opCodes/stmState.js +0 -13
- package/dist/cjs/internal/stm/stm/opCodes/stmState.js.map +0 -1
- package/dist/cjs/internal/stm/stm/opCodes/strategy.js +0 -13
- package/dist/cjs/internal/stm/stm/opCodes/strategy.js.map +0 -1
- package/dist/cjs/internal/stm/stm/opCodes/tExit.js +0 -17
- package/dist/cjs/internal/stm/stm/opCodes/tExit.js.map +0 -1
- package/dist/cjs/internal/stm/stm/opCodes/tryCommit.js +0 -11
- package/dist/cjs/internal/stm/stm/opCodes/tryCommit.js.map +0 -1
- package/dist/cjs/internal/stm/stm/stmState.js.map +0 -1
- package/dist/cjs/internal/stm/stm/tExit.js.map +0 -1
- package/dist/cjs/internal/stm/stm/tryCommit.js.map +0 -1
- package/dist/cjs/internal/stm/stm/txnId.js.map +0 -1
- package/dist/cjs/internal/stm/stm/versioned.js.map +0 -1
- package/dist/dts/internal/stm/stm/entry.d.ts.map +0 -1
- package/dist/dts/internal/stm/stm/journal.d.ts.map +0 -1
- package/dist/dts/internal/stm/stm/opCodes/stm.d.ts +0 -2
- package/dist/dts/internal/stm/stm/opCodes/stm.d.ts.map +0 -1
- package/dist/dts/internal/stm/stm/opCodes/stmState.d.ts.map +0 -1
- package/dist/dts/internal/stm/stm/opCodes/strategy.d.ts +0 -2
- package/dist/dts/internal/stm/stm/opCodes/strategy.d.ts.map +0 -1
- package/dist/dts/internal/stm/stm/opCodes/tExit.d.ts +0 -2
- package/dist/dts/internal/stm/stm/opCodes/tExit.d.ts.map +0 -1
- package/dist/dts/internal/stm/stm/opCodes/tryCommit.d.ts.map +0 -1
- package/dist/dts/internal/stm/stm/stmState.d.ts +0 -2
- package/dist/dts/internal/stm/stm/stmState.d.ts.map +0 -1
- package/dist/dts/internal/stm/stm/tExit.d.ts.map +0 -1
- package/dist/dts/internal/stm/stm/tryCommit.d.ts +0 -2
- package/dist/dts/internal/stm/stm/tryCommit.d.ts.map +0 -1
- package/dist/dts/internal/stm/stm/txnId.d.ts.map +0 -1
- package/dist/dts/internal/stm/stm/versioned.d.ts.map +0 -1
- package/dist/esm/internal/stm/stm/entry.js.map +0 -1
- package/dist/esm/internal/stm/stm/journal.js.map +0 -1
- package/dist/esm/internal/stm/stm/opCodes/stm.js +0 -25
- package/dist/esm/internal/stm/stm/opCodes/stm.js.map +0 -1
- package/dist/esm/internal/stm/stm/opCodes/stmState.js +0 -7
- package/dist/esm/internal/stm/stm/opCodes/stmState.js.map +0 -1
- package/dist/esm/internal/stm/stm/opCodes/strategy.js +0 -7
- package/dist/esm/internal/stm/stm/opCodes/strategy.js.map +0 -1
- package/dist/esm/internal/stm/stm/opCodes/tExit.js +0 -11
- package/dist/esm/internal/stm/stm/opCodes/tExit.js.map +0 -1
- package/dist/esm/internal/stm/stm/opCodes/tryCommit.js +0 -5
- package/dist/esm/internal/stm/stm/opCodes/tryCommit.js.map +0 -1
- package/dist/esm/internal/stm/stm/stmState.js.map +0 -1
- package/dist/esm/internal/stm/stm/tExit.js.map +0 -1
- package/dist/esm/internal/stm/stm/tryCommit.js.map +0 -1
- package/dist/esm/internal/stm/stm/txnId.js.map +0 -1
- package/dist/esm/internal/stm/stm/versioned.js.map +0 -1
- package/src/internal/stm/stm/opCodes/stm.ts +0 -71
- package/src/internal/stm/stm/opCodes/stmState.ts +0 -17
- package/src/internal/stm/stm/opCodes/strategy.ts +0 -17
- package/src/internal/stm/stm/opCodes/tExit.ts +0 -29
- package/src/internal/stm/stm/opCodes/tryCommit.ts +0 -11
- /package/dist/cjs/internal/stm/{stm/entry.js → entry.js} +0 -0
- /package/dist/cjs/internal/stm/{stm/journal.js → journal.js} +0 -0
- /package/dist/cjs/internal/stm/{stm/txnId.js → txnId.js} +0 -0
- /package/dist/cjs/internal/stm/{stm/versioned.js → versioned.js} +0 -0
- /package/dist/dts/internal/stm/{stm/entry.d.ts → entry.d.ts} +0 -0
- /package/dist/dts/internal/stm/{stm/journal.d.ts → journal.d.ts} +0 -0
- /package/dist/dts/internal/stm/{stm/opCodes/stmState.d.ts → stmState.d.ts} +0 -0
- /package/dist/dts/internal/stm/{stm/tExit.d.ts → tExit.d.ts} +0 -0
- /package/dist/dts/internal/stm/{stm/opCodes/tryCommit.d.ts → tryCommit.d.ts} +0 -0
- /package/dist/dts/internal/stm/{stm/txnId.d.ts → txnId.d.ts} +0 -0
- /package/dist/dts/internal/stm/{stm/versioned.d.ts → versioned.d.ts} +0 -0
- /package/dist/esm/internal/stm/{stm/entry.js → entry.js} +0 -0
- /package/dist/esm/internal/stm/{stm/journal.js → journal.js} +0 -0
- /package/dist/esm/internal/stm/{stm/txnId.js → txnId.js} +0 -0
- /package/dist/esm/internal/stm/{stm/versioned.js → versioned.js} +0 -0
- /package/src/internal/stm/{stm/txnId.ts → txnId.ts} +0 -0
- /package/src/internal/stm/{stm/versioned.ts → versioned.ts} +0 -0
package/dist/esm/Schema.js
CHANGED
|
@@ -34,7 +34,6 @@ import * as option_ from "./Option.js";
|
|
|
34
34
|
import * as ParseResult from "./ParseResult.js";
|
|
35
35
|
import { pipeArguments } from "./Pipeable.js";
|
|
36
36
|
import * as Predicate from "./Predicate.js";
|
|
37
|
-
import * as record_ from "./Record.js";
|
|
38
37
|
import * as redacted_ from "./Redacted.js";
|
|
39
38
|
import * as Request from "./Request.js";
|
|
40
39
|
import * as scheduler_ from "./Scheduler.js";
|
|
@@ -51,23 +50,25 @@ export const TypeId = /*#__PURE__*/Symbol.for("effect/Schema");
|
|
|
51
50
|
* @category constructors
|
|
52
51
|
* @since 3.10.0
|
|
53
52
|
*/
|
|
54
|
-
export
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
53
|
+
export function make(ast) {
|
|
54
|
+
return class SchemaClass {
|
|
55
|
+
[TypeId] = variance;
|
|
56
|
+
static ast = ast;
|
|
57
|
+
static annotations(annotations) {
|
|
58
|
+
return make(mergeSchemaAnnotations(this.ast, annotations));
|
|
59
|
+
}
|
|
60
|
+
static pipe() {
|
|
61
|
+
return pipeArguments(this, arguments);
|
|
62
|
+
}
|
|
63
|
+
static toString() {
|
|
64
|
+
return String(ast);
|
|
65
|
+
}
|
|
66
|
+
static Type;
|
|
67
|
+
static Encoded;
|
|
68
|
+
static Context;
|
|
69
|
+
static [TypeId] = variance;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
71
72
|
const variance = {
|
|
72
73
|
/* c8 ignore next */
|
|
73
74
|
_A: _ => _,
|
|
@@ -186,7 +187,9 @@ const mergeSchemaAnnotations = (ast, annotations) => AST.annotations(ast, toASTA
|
|
|
186
187
|
/**
|
|
187
188
|
* @since 3.10.0
|
|
188
189
|
*/
|
|
189
|
-
export
|
|
190
|
+
export function asSchema(schema) {
|
|
191
|
+
return schema;
|
|
192
|
+
}
|
|
190
193
|
/**
|
|
191
194
|
* @category formatting
|
|
192
195
|
* @since 3.10.0
|
|
@@ -399,13 +402,17 @@ export const validatePromise = (schema, options) => {
|
|
|
399
402
|
* @since 3.10.0
|
|
400
403
|
*/
|
|
401
404
|
export const isSchema = u => Predicate.hasProperty(u, TypeId) && Predicate.isObject(u[TypeId]);
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
405
|
+
function getDefaultLiteralAST(literals) {
|
|
406
|
+
return AST.isMembers(literals) ? AST.Union.make(AST.mapMembers(literals, literal => new AST.Literal(literal))) : new AST.Literal(literals[0]);
|
|
407
|
+
}
|
|
408
|
+
function makeLiteralClass(literals, ast = getDefaultLiteralAST(literals)) {
|
|
409
|
+
return class LiteralClass extends make(ast) {
|
|
410
|
+
static annotations(annotations) {
|
|
411
|
+
return makeLiteralClass(this.literals, mergeSchemaAnnotations(this.ast, annotations));
|
|
412
|
+
}
|
|
413
|
+
static literals = [...literals];
|
|
414
|
+
};
|
|
415
|
+
}
|
|
409
416
|
export function Literal(...literals) {
|
|
410
417
|
return array_.isNonEmptyReadonlyArray(literals) ? makeLiteralClass(literals) : Never;
|
|
411
418
|
}
|
|
@@ -560,21 +567,29 @@ export const TemplateLiteralParser = (...params) => {
|
|
|
560
567
|
}
|
|
561
568
|
return class TemplateLiteralParserClass extends transformOrFail(from, to, {
|
|
562
569
|
strict: false,
|
|
563
|
-
decode: (
|
|
564
|
-
const match = re.exec(
|
|
565
|
-
return match ? ParseResult.succeed(match.slice(1, params.length + 1)) : ParseResult.fail(new ParseResult.Type(ast,
|
|
570
|
+
decode: (i, _, ast) => {
|
|
571
|
+
const match = re.exec(i);
|
|
572
|
+
return match ? ParseResult.succeed(match.slice(1, params.length + 1)) : ParseResult.fail(new ParseResult.Type(ast, i, `${re.source}: no match for ${JSON.stringify(i)}`));
|
|
566
573
|
},
|
|
567
574
|
encode: tuple => ParseResult.succeed(tuple.join(""))
|
|
568
575
|
}) {
|
|
569
576
|
static params = params.slice();
|
|
570
577
|
};
|
|
571
578
|
};
|
|
572
|
-
const declareConstructor = (typeParameters, options, annotations) =>
|
|
579
|
+
const declareConstructor = (typeParameters, options, annotations) => makeDeclareClass(typeParameters, new AST.Declaration(typeParameters.map(tp => tp.ast), (...typeParameters) => options.decode(...typeParameters.map(make)), (...typeParameters) => options.encode(...typeParameters.map(make)), toASTAnnotations(annotations)));
|
|
573
580
|
const declarePrimitive = (is, annotations) => {
|
|
574
581
|
const decodeUnknown = () => (input, _, ast) => is(input) ? ParseResult.succeed(input) : ParseResult.fail(new ParseResult.Type(ast, input));
|
|
575
582
|
const encodeUnknown = decodeUnknown;
|
|
576
|
-
return
|
|
583
|
+
return makeDeclareClass([], new AST.Declaration([], decodeUnknown, encodeUnknown, toASTAnnotations(annotations)));
|
|
577
584
|
};
|
|
585
|
+
function makeDeclareClass(typeParameters, ast) {
|
|
586
|
+
return class DeclareClass extends make(ast) {
|
|
587
|
+
static annotations(annotations) {
|
|
588
|
+
return makeDeclareClass(this.typeParameters, mergeSchemaAnnotations(this.ast, annotations));
|
|
589
|
+
}
|
|
590
|
+
static typeParameters = [...typeParameters];
|
|
591
|
+
};
|
|
592
|
+
}
|
|
578
593
|
/**
|
|
579
594
|
* The constraint `R extends Schema.Context<P[number]>` enforces dependencies solely from `typeParameters`.
|
|
580
595
|
* This ensures that when you call `Schema.to` or `Schema.from`, you receive a schema with a `never` context.
|
|
@@ -602,16 +617,19 @@ export const BrandSchemaId = /*#__PURE__*/Symbol.for("effect/SchemaId/Brand");
|
|
|
602
617
|
* @category constructors
|
|
603
618
|
* @since 3.10.0
|
|
604
619
|
*/
|
|
605
|
-
export const fromBrand = (constructor, annotations) => self =>
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
620
|
+
export const fromBrand = (constructor, annotations) => self => {
|
|
621
|
+
const out = makeBrandClass(self, new AST.Refinement(self.ast, function predicate(a, _, ast) {
|
|
622
|
+
const either = constructor.either(a);
|
|
623
|
+
return either_.isLeft(either) ? option_.some(new ParseResult.Type(ast, a, either.left.map(v => v.message).join(", "))) : option_.none();
|
|
624
|
+
}, toASTAnnotations({
|
|
625
|
+
schemaId: BrandSchemaId,
|
|
626
|
+
[BrandSchemaId]: {
|
|
627
|
+
constructor
|
|
628
|
+
},
|
|
629
|
+
...annotations
|
|
630
|
+
})));
|
|
631
|
+
return out;
|
|
632
|
+
};
|
|
615
633
|
/**
|
|
616
634
|
* @category schema id
|
|
617
635
|
* @since 3.10.0
|
|
@@ -701,12 +719,14 @@ Object$ as Object,
|
|
|
701
719
|
*/
|
|
702
720
|
String$ as String };
|
|
703
721
|
const getDefaultUnionAST = members => AST.Union.make(members.map(m => m.ast));
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
722
|
+
function makeUnionClass(members, ast = getDefaultUnionAST(members)) {
|
|
723
|
+
return class UnionClass extends make(ast) {
|
|
724
|
+
static annotations(annotations) {
|
|
725
|
+
return makeUnionClass(this.members, mergeSchemaAnnotations(this.ast, annotations));
|
|
726
|
+
}
|
|
727
|
+
static members = [...members];
|
|
728
|
+
};
|
|
729
|
+
}
|
|
710
730
|
export function Union(...members) {
|
|
711
731
|
return AST.isMembers(members) ? makeUnionClass(members) : array_.isNonEmptyReadonlyArray(members) ? members[0] : Never;
|
|
712
732
|
}
|
|
@@ -758,22 +778,26 @@ class ElementImpl {
|
|
|
758
778
|
}
|
|
759
779
|
}
|
|
760
780
|
const getDefaultTupleTypeAST = (elements, rest) => new AST.TupleType(elements.map(el => isSchema(el) ? new AST.OptionalType(el.ast, false) : el.ast), rest.map(el => isSchema(el) ? new AST.Type(el.ast) : el.ast), true);
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
781
|
+
function makeTupleTypeClass(elements, rest, ast = getDefaultTupleTypeAST(elements, rest)) {
|
|
782
|
+
return class TupleTypeClass extends make(ast) {
|
|
783
|
+
static annotations(annotations) {
|
|
784
|
+
return makeTupleTypeClass(this.elements, this.rest, mergeSchemaAnnotations(this.ast, annotations));
|
|
785
|
+
}
|
|
786
|
+
static elements = [...elements];
|
|
787
|
+
static rest = [...rest];
|
|
788
|
+
};
|
|
789
|
+
}
|
|
768
790
|
export function Tuple(...args) {
|
|
769
791
|
return Array.isArray(args[0]) ? makeTupleTypeClass(args[0], args.slice(1)) : makeTupleTypeClass(args, []);
|
|
770
792
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
793
|
+
function makeArrayClass(value, ast) {
|
|
794
|
+
return class ArrayClass extends makeTupleTypeClass([], [value], ast) {
|
|
795
|
+
static annotations(annotations) {
|
|
796
|
+
return makeArrayClass(this.value, mergeSchemaAnnotations(this.ast, annotations));
|
|
797
|
+
}
|
|
798
|
+
static value = value;
|
|
799
|
+
};
|
|
800
|
+
}
|
|
777
801
|
const Array$ = value => makeArrayClass(value);
|
|
778
802
|
export {
|
|
779
803
|
/**
|
|
@@ -781,12 +805,14 @@ export {
|
|
|
781
805
|
* @since 3.10.0
|
|
782
806
|
*/
|
|
783
807
|
Array$ as Array };
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
808
|
+
function makeNonEmptyArrayClass(value, ast) {
|
|
809
|
+
return class NonEmptyArrayClass extends makeTupleTypeClass([value], [value], ast) {
|
|
810
|
+
static annotations(annotations) {
|
|
811
|
+
return makeNonEmptyArrayClass(this.value, mergeSchemaAnnotations(this.ast, annotations));
|
|
812
|
+
}
|
|
813
|
+
static value = value;
|
|
814
|
+
};
|
|
815
|
+
}
|
|
790
816
|
/**
|
|
791
817
|
* @category constructors
|
|
792
818
|
* @since 3.10.0
|
|
@@ -796,26 +822,24 @@ export const NonEmptyArray = value => makeNonEmptyArrayClass(value);
|
|
|
796
822
|
* @category constructors
|
|
797
823
|
* @since 3.10.0
|
|
798
824
|
*/
|
|
799
|
-
export
|
|
800
|
-
|
|
801
|
-
return class ArrayEnsureClass extends transform(Union(value_, Array$(value_)), Array$(typeSchema(value_)), {
|
|
825
|
+
export function ArrayEnsure(value) {
|
|
826
|
+
return transform(Union(value, Array$(value)), Array$(typeSchema(asSchema(value))), {
|
|
802
827
|
strict: true,
|
|
803
|
-
decode: array_.ensure,
|
|
804
|
-
encode:
|
|
805
|
-
})
|
|
806
|
-
}
|
|
828
|
+
decode: i => array_.ensure(i),
|
|
829
|
+
encode: a => a.length === 1 ? a[0] : a
|
|
830
|
+
});
|
|
831
|
+
}
|
|
807
832
|
/**
|
|
808
833
|
* @category constructors
|
|
809
834
|
* @since 3.10.0
|
|
810
835
|
*/
|
|
811
|
-
export
|
|
812
|
-
|
|
813
|
-
return class NonEmptyArrayEnsureClass extends transform(Union(value_, NonEmptyArray(value_)), NonEmptyArray(typeSchema(value_)), {
|
|
836
|
+
export function NonEmptyArrayEnsure(value) {
|
|
837
|
+
return transform(Union(value, NonEmptyArray(value)), NonEmptyArray(typeSchema(asSchema(value))), {
|
|
814
838
|
strict: true,
|
|
815
|
-
decode: array_.
|
|
816
|
-
encode:
|
|
817
|
-
})
|
|
818
|
-
}
|
|
839
|
+
decode: i => array_.isNonEmptyReadonlyArray(i) ? i : array_.of(i),
|
|
840
|
+
encode: a => a.length === 1 ? a[0] : a
|
|
841
|
+
});
|
|
842
|
+
}
|
|
819
843
|
const formatPropertySignatureToken = isOptional => isOptional ? "\"?:\"" : "\":\"";
|
|
820
844
|
/**
|
|
821
845
|
* @category PropertySignature
|
|
@@ -1402,22 +1426,26 @@ export const omit = (...keys) => self => make(AST.omit(self.ast, keys));
|
|
|
1402
1426
|
export const pluck = /*#__PURE__*/dual(2, (schema, key) => {
|
|
1403
1427
|
const ps = AST.getPropertyKeyIndexedAccess(AST.typeAST(schema.ast), key);
|
|
1404
1428
|
const value = make(ps.isOptional ? AST.orUndefined(ps.type) : ps.type);
|
|
1405
|
-
|
|
1429
|
+
const out = transform(schema.pipe(pick(key)), value, {
|
|
1406
1430
|
strict: true,
|
|
1407
|
-
decode:
|
|
1408
|
-
encode:
|
|
1409
|
-
[key]:
|
|
1431
|
+
decode: i => i[key],
|
|
1432
|
+
encode: a => ps.isOptional && a === undefined ? {} : {
|
|
1433
|
+
[key]: a
|
|
1410
1434
|
}
|
|
1411
1435
|
});
|
|
1436
|
+
return out;
|
|
1412
1437
|
});
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1438
|
+
function makeBrandClass(from, ast) {
|
|
1439
|
+
return class BrandClass extends make(ast) {
|
|
1440
|
+
static annotations(annotations) {
|
|
1441
|
+
return makeBrandClass(this.from, mergeSchemaAnnotations(this.ast, annotations));
|
|
1442
|
+
}
|
|
1443
|
+
static make = (a, options) => {
|
|
1444
|
+
return getDisableValidationMakeOption(options) ? a : ParseResult.validateSync(this)(a);
|
|
1445
|
+
};
|
|
1446
|
+
static from = from;
|
|
1419
1447
|
};
|
|
1420
|
-
}
|
|
1448
|
+
}
|
|
1421
1449
|
/**
|
|
1422
1450
|
* Returns a nominal branded schema by applying a brand to a given schema.
|
|
1423
1451
|
*
|
|
@@ -1448,7 +1476,7 @@ export const brand = (brand, annotations) => self => {
|
|
|
1448
1476
|
[AST.BrandAnnotationId]: annotation,
|
|
1449
1477
|
...annotations
|
|
1450
1478
|
}));
|
|
1451
|
-
return makeBrandClass(ast);
|
|
1479
|
+
return makeBrandClass(self, ast);
|
|
1452
1480
|
};
|
|
1453
1481
|
/**
|
|
1454
1482
|
* @category combinators
|
|
@@ -1647,7 +1675,7 @@ export const extend = /*#__PURE__*/dual(2, (self, that) => make(extendAST(self.a
|
|
|
1647
1675
|
* @category combinators
|
|
1648
1676
|
* @since 3.10.0
|
|
1649
1677
|
*/
|
|
1650
|
-
export const compose = /*#__PURE__*/dual(args => isSchema(args[1]), (from, to) =>
|
|
1678
|
+
export const compose = /*#__PURE__*/dual(args => isSchema(args[1]), (from, to) => makeTransformationClass(from, to, AST.compose(from.ast, to.ast)));
|
|
1651
1679
|
/**
|
|
1652
1680
|
* @category constructors
|
|
1653
1681
|
* @since 3.10.0
|
|
@@ -1658,17 +1686,19 @@ export const suspend = f => make(new AST.Suspend(() => f().ast));
|
|
|
1658
1686
|
* @category symbol
|
|
1659
1687
|
*/
|
|
1660
1688
|
export const RefineSchemaId = /*#__PURE__*/Symbol.for("effect/SchemaId/Refine");
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1689
|
+
function makeRefineClass(from, filter, ast) {
|
|
1690
|
+
return class RefineClass extends make(ast) {
|
|
1691
|
+
static annotations(annotations) {
|
|
1692
|
+
return makeRefineClass(this.from, this.filter, mergeSchemaAnnotations(this.ast, annotations));
|
|
1693
|
+
}
|
|
1694
|
+
static [RefineSchemaId] = from;
|
|
1695
|
+
static from = from;
|
|
1696
|
+
static filter = filter;
|
|
1697
|
+
static make = (a, options) => {
|
|
1698
|
+
return getDisableValidationMakeOption(options) ? a : ParseResult.validateSync(this)(a);
|
|
1699
|
+
};
|
|
1670
1700
|
};
|
|
1671
|
-
}
|
|
1701
|
+
}
|
|
1672
1702
|
const fromFilterPredicateReturnTypeItem = (item, ast, input) => {
|
|
1673
1703
|
if (Predicate.isBoolean(item)) {
|
|
1674
1704
|
return item ? option_.none() : option_.some(new ParseResult.Type(ast, input));
|
|
@@ -1712,19 +1742,21 @@ export function filter(predicate, annotations) {
|
|
|
1712
1742
|
*/
|
|
1713
1743
|
export const filterEffect = /*#__PURE__*/dual(2, (self, f) => transformOrFail(self, typeSchema(self), {
|
|
1714
1744
|
strict: true,
|
|
1715
|
-
decode: (
|
|
1716
|
-
onNone: () => ParseResult.succeed(
|
|
1745
|
+
decode: (i, options, ast) => ParseResult.flatMap(f(i, options, ast), filterReturnType => option_.match(toFilterParseIssue(filterReturnType, ast, i), {
|
|
1746
|
+
onNone: () => ParseResult.succeed(i),
|
|
1717
1747
|
onSome: ParseResult.fail
|
|
1718
1748
|
})),
|
|
1719
|
-
encode: ParseResult.succeed
|
|
1749
|
+
encode: a => ParseResult.succeed(a)
|
|
1720
1750
|
}));
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1751
|
+
function makeTransformationClass(from, to, ast) {
|
|
1752
|
+
return class TransformationClass extends make(ast) {
|
|
1753
|
+
static annotations(annotations) {
|
|
1754
|
+
return makeTransformationClass(this.from, this.to, mergeSchemaAnnotations(this.ast, annotations));
|
|
1755
|
+
}
|
|
1756
|
+
static from = from;
|
|
1757
|
+
static to = to;
|
|
1758
|
+
};
|
|
1759
|
+
}
|
|
1728
1760
|
/**
|
|
1729
1761
|
* Create a new `Schema` by transforming the input and output of an existing `Schema`
|
|
1730
1762
|
* using the provided decoding functions.
|
|
@@ -1760,11 +1792,13 @@ export const transform = /*#__PURE__*/dual(args => isSchema(args[0]) && isSchema
|
|
|
1760
1792
|
* @category constructors
|
|
1761
1793
|
* @since 3.10.0
|
|
1762
1794
|
*/
|
|
1763
|
-
export
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1795
|
+
export function transformLiteral(from, to) {
|
|
1796
|
+
return transform(Literal(from), Literal(to), {
|
|
1797
|
+
strict: true,
|
|
1798
|
+
decode: () => to,
|
|
1799
|
+
encode: () => from
|
|
1800
|
+
});
|
|
1801
|
+
}
|
|
1768
1802
|
export function transformLiterals(...pairs) {
|
|
1769
1803
|
return Union(...pairs.map(([from, to]) => transformLiteral(from, to)));
|
|
1770
1804
|
}
|
|
@@ -1876,6 +1910,41 @@ export const minLength = (minLength, annotations) => self => self.pipe(filter(a
|
|
|
1876
1910
|
},
|
|
1877
1911
|
...annotations
|
|
1878
1912
|
}));
|
|
1913
|
+
/**
|
|
1914
|
+
* @category schema id
|
|
1915
|
+
* @since 3.10.0
|
|
1916
|
+
*/
|
|
1917
|
+
export const LengthSchemaId = schemaId_.LengthSchemaId;
|
|
1918
|
+
/**
|
|
1919
|
+
* @category string filters
|
|
1920
|
+
* @since 3.10.0
|
|
1921
|
+
*/
|
|
1922
|
+
export const length = (length, annotations) => self => {
|
|
1923
|
+
const minLength = Predicate.isObject(length) ? Math.max(0, Math.floor(length.min)) : Math.max(0, Math.floor(length));
|
|
1924
|
+
const maxLength = Predicate.isObject(length) ? Math.max(minLength, Math.floor(length.max)) : minLength;
|
|
1925
|
+
if (minLength !== maxLength) {
|
|
1926
|
+
return self.pipe(filter(a => a.length >= minLength && a.length <= maxLength, {
|
|
1927
|
+
schemaId: LengthSchemaId,
|
|
1928
|
+
title: `length({ min: ${minLength}, max: ${maxLength})`,
|
|
1929
|
+
description: `a string at least ${minLength} character(s) and at most ${maxLength} character(s) long`,
|
|
1930
|
+
jsonSchema: {
|
|
1931
|
+
minLength,
|
|
1932
|
+
maxLength
|
|
1933
|
+
},
|
|
1934
|
+
...annotations
|
|
1935
|
+
}));
|
|
1936
|
+
}
|
|
1937
|
+
return self.pipe(filter(a => a.length === minLength, {
|
|
1938
|
+
schemaId: LengthSchemaId,
|
|
1939
|
+
title: `length(${minLength})`,
|
|
1940
|
+
description: minLength === 1 ? `a single character` : `a string ${minLength} character(s) long`,
|
|
1941
|
+
jsonSchema: {
|
|
1942
|
+
minLength,
|
|
1943
|
+
maxLength: minLength
|
|
1944
|
+
},
|
|
1945
|
+
...annotations
|
|
1946
|
+
}));
|
|
1947
|
+
};
|
|
1879
1948
|
/**
|
|
1880
1949
|
* @category schema id
|
|
1881
1950
|
* @since 3.10.0
|
|
@@ -2007,19 +2076,19 @@ export class Lowercased extends /*#__PURE__*/String$.pipe( /*#__PURE__*/lowercas
|
|
|
2007
2076
|
* @category schema id
|
|
2008
2077
|
* @since 3.10.0
|
|
2009
2078
|
*/
|
|
2010
|
-
export const
|
|
2079
|
+
export const UppercasedSchemaId = /*#__PURE__*/Symbol.for("effect/SchemaId/Uppercased");
|
|
2011
2080
|
/**
|
|
2012
|
-
* Verifies that a string is
|
|
2081
|
+
* Verifies that a string is uppercased.
|
|
2013
2082
|
*
|
|
2014
2083
|
* @category string filters
|
|
2015
2084
|
* @since 3.10.0
|
|
2016
2085
|
*/
|
|
2017
|
-
export const
|
|
2018
|
-
schemaId:
|
|
2019
|
-
title: "
|
|
2020
|
-
description: "
|
|
2086
|
+
export const uppercased = annotations => self => self.pipe(filter(a => a === a.toUpperCase(), {
|
|
2087
|
+
schemaId: UppercasedSchemaId,
|
|
2088
|
+
title: "uppercased",
|
|
2089
|
+
description: "an uppercase string",
|
|
2021
2090
|
jsonSchema: {
|
|
2022
|
-
pattern: "^[^a-z]
|
|
2091
|
+
pattern: "^[^a-z]*$"
|
|
2023
2092
|
},
|
|
2024
2093
|
...annotations
|
|
2025
2094
|
}));
|
|
@@ -2027,26 +2096,26 @@ export const capitalized = annotations => self => self.pipe(filter(a => a[0]?.to
|
|
|
2027
2096
|
* @category string constructors
|
|
2028
2097
|
* @since 3.10.0
|
|
2029
2098
|
*/
|
|
2030
|
-
export class
|
|
2031
|
-
identifier: "
|
|
2099
|
+
export class Uppercased extends /*#__PURE__*/String$.pipe( /*#__PURE__*/uppercased({
|
|
2100
|
+
identifier: "Uppercased"
|
|
2032
2101
|
})) {}
|
|
2033
2102
|
/**
|
|
2034
2103
|
* @category schema id
|
|
2035
2104
|
* @since 3.10.0
|
|
2036
2105
|
*/
|
|
2037
|
-
export const
|
|
2106
|
+
export const CapitalizedSchemaId = /*#__PURE__*/Symbol.for("effect/SchemaId/Capitalized");
|
|
2038
2107
|
/**
|
|
2039
|
-
* Verifies that a string is
|
|
2108
|
+
* Verifies that a string is capitalized.
|
|
2040
2109
|
*
|
|
2041
2110
|
* @category string filters
|
|
2042
2111
|
* @since 3.10.0
|
|
2043
2112
|
*/
|
|
2044
|
-
export const
|
|
2045
|
-
schemaId:
|
|
2046
|
-
title: "
|
|
2047
|
-
description: "a
|
|
2113
|
+
export const capitalized = annotations => self => self.pipe(filter(a => a[0]?.toUpperCase() === a[0], {
|
|
2114
|
+
schemaId: CapitalizedSchemaId,
|
|
2115
|
+
title: "capitalized",
|
|
2116
|
+
description: "a capitalized string",
|
|
2048
2117
|
jsonSchema: {
|
|
2049
|
-
pattern: "^[^
|
|
2118
|
+
pattern: "^[^a-z]?.*$"
|
|
2050
2119
|
},
|
|
2051
2120
|
...annotations
|
|
2052
2121
|
}));
|
|
@@ -2054,26 +2123,26 @@ export const uncapitalized = annotations => self => self.pipe(filter(a => a[0]?.
|
|
|
2054
2123
|
* @category string constructors
|
|
2055
2124
|
* @since 3.10.0
|
|
2056
2125
|
*/
|
|
2057
|
-
export class
|
|
2058
|
-
identifier: "
|
|
2126
|
+
export class Capitalized extends /*#__PURE__*/String$.pipe( /*#__PURE__*/capitalized({
|
|
2127
|
+
identifier: "Capitalized"
|
|
2059
2128
|
})) {}
|
|
2060
2129
|
/**
|
|
2061
2130
|
* @category schema id
|
|
2062
2131
|
* @since 3.10.0
|
|
2063
2132
|
*/
|
|
2064
|
-
export const
|
|
2133
|
+
export const UncapitalizedSchemaId = /*#__PURE__*/Symbol.for("effect/SchemaId/Uncapitalized");
|
|
2065
2134
|
/**
|
|
2066
|
-
* Verifies that a string is
|
|
2135
|
+
* Verifies that a string is uncapitalized.
|
|
2067
2136
|
*
|
|
2068
2137
|
* @category string filters
|
|
2069
2138
|
* @since 3.10.0
|
|
2070
2139
|
*/
|
|
2071
|
-
export const
|
|
2072
|
-
schemaId:
|
|
2073
|
-
title: "
|
|
2074
|
-
description: "
|
|
2140
|
+
export const uncapitalized = annotations => self => self.pipe(filter(a => a[0]?.toLowerCase() === a[0], {
|
|
2141
|
+
schemaId: UncapitalizedSchemaId,
|
|
2142
|
+
title: "uncapitalized",
|
|
2143
|
+
description: "a uncapitalized string",
|
|
2075
2144
|
jsonSchema: {
|
|
2076
|
-
pattern: "^[^
|
|
2145
|
+
pattern: "^[^A-Z]?.*$"
|
|
2077
2146
|
},
|
|
2078
2147
|
...annotations
|
|
2079
2148
|
}));
|
|
@@ -2081,44 +2150,9 @@ export const uppercased = annotations => self => self.pipe(filter(a => a === a.t
|
|
|
2081
2150
|
* @category string constructors
|
|
2082
2151
|
* @since 3.10.0
|
|
2083
2152
|
*/
|
|
2084
|
-
export class
|
|
2085
|
-
identifier: "
|
|
2153
|
+
export class Uncapitalized extends /*#__PURE__*/String$.pipe( /*#__PURE__*/uncapitalized({
|
|
2154
|
+
identifier: "Uncapitalized"
|
|
2086
2155
|
})) {}
|
|
2087
|
-
/**
|
|
2088
|
-
* @category schema id
|
|
2089
|
-
* @since 3.10.0
|
|
2090
|
-
*/
|
|
2091
|
-
export const LengthSchemaId = schemaId_.LengthSchemaId;
|
|
2092
|
-
/**
|
|
2093
|
-
* @category string filters
|
|
2094
|
-
* @since 3.10.0
|
|
2095
|
-
*/
|
|
2096
|
-
export const length = (length, annotations) => self => {
|
|
2097
|
-
const minLength = Predicate.isObject(length) ? Math.max(0, Math.floor(length.min)) : Math.max(0, Math.floor(length));
|
|
2098
|
-
const maxLength = Predicate.isObject(length) ? Math.max(minLength, Math.floor(length.max)) : minLength;
|
|
2099
|
-
if (minLength !== maxLength) {
|
|
2100
|
-
return self.pipe(filter(a => a.length >= minLength && a.length <= maxLength, {
|
|
2101
|
-
schemaId: LengthSchemaId,
|
|
2102
|
-
title: `length({ min: ${minLength}, max: ${maxLength})`,
|
|
2103
|
-
description: `a string at least ${minLength} character(s) and at most ${maxLength} character(s) long`,
|
|
2104
|
-
jsonSchema: {
|
|
2105
|
-
minLength,
|
|
2106
|
-
maxLength
|
|
2107
|
-
},
|
|
2108
|
-
...annotations
|
|
2109
|
-
}));
|
|
2110
|
-
}
|
|
2111
|
-
return self.pipe(filter(a => a.length === minLength, {
|
|
2112
|
-
schemaId: LengthSchemaId,
|
|
2113
|
-
title: `length(${minLength})`,
|
|
2114
|
-
description: minLength === 1 ? `a single character` : `a string ${minLength} character(s) long`,
|
|
2115
|
-
jsonSchema: {
|
|
2116
|
-
minLength,
|
|
2117
|
-
maxLength: minLength
|
|
2118
|
-
},
|
|
2119
|
-
...annotations
|
|
2120
|
-
}));
|
|
2121
|
-
};
|
|
2122
2156
|
/**
|
|
2123
2157
|
* A schema representing a single character.
|
|
2124
2158
|
*
|
|
@@ -2147,7 +2181,7 @@ export class Lowercase extends /*#__PURE__*/transform(String$.annotations({
|
|
|
2147
2181
|
description: "a string that will be converted to lowercase"
|
|
2148
2182
|
}), Lowercased, {
|
|
2149
2183
|
strict: true,
|
|
2150
|
-
decode:
|
|
2184
|
+
decode: i => i.toLowerCase(),
|
|
2151
2185
|
encode: identity
|
|
2152
2186
|
}).annotations({
|
|
2153
2187
|
identifier: "Lowercase"
|
|
@@ -2162,7 +2196,7 @@ export class Uppercase extends /*#__PURE__*/transform(String$.annotations({
|
|
|
2162
2196
|
description: "a string that will be converted to uppercase"
|
|
2163
2197
|
}), Uppercased, {
|
|
2164
2198
|
strict: true,
|
|
2165
|
-
decode:
|
|
2199
|
+
decode: i => i.toUpperCase(),
|
|
2166
2200
|
encode: identity
|
|
2167
2201
|
}).annotations({
|
|
2168
2202
|
identifier: "Uppercase"
|
|
@@ -2177,7 +2211,7 @@ export class Capitalize extends /*#__PURE__*/transform(String$.annotations({
|
|
|
2177
2211
|
description: "a string that will be converted to a capitalized format"
|
|
2178
2212
|
}), Capitalized, {
|
|
2179
2213
|
strict: true,
|
|
2180
|
-
decode:
|
|
2214
|
+
decode: i => string_.capitalize(i),
|
|
2181
2215
|
encode: identity
|
|
2182
2216
|
}).annotations({
|
|
2183
2217
|
identifier: "Capitalize"
|
|
@@ -2192,7 +2226,7 @@ export class Uncapitalize extends /*#__PURE__*/transform(String$.annotations({
|
|
|
2192
2226
|
description: "a string that will be converted to an uncapitalized format"
|
|
2193
2227
|
}), Uncapitalized, {
|
|
2194
2228
|
strict: true,
|
|
2195
|
-
decode:
|
|
2229
|
+
decode: i => string_.uncapitalize(i),
|
|
2196
2230
|
encode: identity
|
|
2197
2231
|
}).annotations({
|
|
2198
2232
|
identifier: "Uncapitalize"
|
|
@@ -2233,7 +2267,7 @@ export class Trim extends /*#__PURE__*/transform(String$.annotations({
|
|
|
2233
2267
|
description: "a string that will be trimmed"
|
|
2234
2268
|
}), Trimmed, {
|
|
2235
2269
|
strict: true,
|
|
2236
|
-
decode:
|
|
2270
|
+
decode: i => i.trim(),
|
|
2237
2271
|
encode: identity
|
|
2238
2272
|
}).annotations({
|
|
2239
2273
|
identifier: "Trim"
|
|
@@ -2248,21 +2282,21 @@ export const split = separator => transform(String$.annotations({
|
|
|
2248
2282
|
description: "a string that will be split"
|
|
2249
2283
|
}), Array$(String$), {
|
|
2250
2284
|
strict: true,
|
|
2251
|
-
decode:
|
|
2252
|
-
encode:
|
|
2285
|
+
decode: i => i.split(separator),
|
|
2286
|
+
encode: a => a.join(separator)
|
|
2253
2287
|
});
|
|
2254
2288
|
const getErrorMessage = e => e instanceof Error ? e.message : String(e);
|
|
2255
2289
|
const getParseJsonTransformation = options => transformOrFail(String$.annotations({
|
|
2256
|
-
|
|
2290
|
+
description: "a string to be decoded into JSON"
|
|
2257
2291
|
}), Unknown, {
|
|
2258
2292
|
strict: true,
|
|
2259
|
-
decode: (
|
|
2260
|
-
try: () => JSON.parse(
|
|
2261
|
-
catch: e => new ParseResult.Type(ast,
|
|
2293
|
+
decode: (i, _, ast) => ParseResult.try({
|
|
2294
|
+
try: () => JSON.parse(i, options?.reviver),
|
|
2295
|
+
catch: e => new ParseResult.Type(ast, i, getErrorMessage(e))
|
|
2262
2296
|
}),
|
|
2263
|
-
encode: (
|
|
2264
|
-
try: () => JSON.stringify(
|
|
2265
|
-
catch: e => new ParseResult.Type(ast,
|
|
2297
|
+
encode: (a, _, ast) => ParseResult.try({
|
|
2298
|
+
try: () => JSON.stringify(a, options?.replacer, options?.space),
|
|
2299
|
+
catch: e => new ParseResult.Type(ast, a, getErrorMessage(e))
|
|
2266
2300
|
})
|
|
2267
2301
|
}).annotations({
|
|
2268
2302
|
title: "parseJson",
|
|
@@ -2356,11 +2390,11 @@ class URL$ extends /*#__PURE__*/transformOrFail(String$.annotations({
|
|
|
2356
2390
|
description: "a string to be decoded into a URL"
|
|
2357
2391
|
}), URLFromSelf, {
|
|
2358
2392
|
strict: true,
|
|
2359
|
-
decode: (
|
|
2360
|
-
try: () => new URL(
|
|
2361
|
-
catch: e => new ParseResult.Type(ast,
|
|
2393
|
+
decode: (i, _, ast) => ParseResult.try({
|
|
2394
|
+
try: () => new URL(i),
|
|
2395
|
+
catch: e => new ParseResult.Type(ast, i, `Unable to decode ${JSON.stringify(i)} into a URL. ${getErrorMessage(e)}`)
|
|
2362
2396
|
}),
|
|
2363
|
-
encode:
|
|
2397
|
+
encode: a => ParseResult.succeed(a.toString())
|
|
2364
2398
|
}).annotations({
|
|
2365
2399
|
identifier: "URL",
|
|
2366
2400
|
pretty: () => url => url.toString()
|
|
@@ -2589,29 +2623,36 @@ export const nonNegative = annotations => greaterThanOrEqualTo(0, {
|
|
|
2589
2623
|
* @category number transformations
|
|
2590
2624
|
* @since 3.10.0
|
|
2591
2625
|
*/
|
|
2592
|
-
export const clamp = (minimum, maximum) => self =>
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2626
|
+
export const clamp = (minimum, maximum) => self => {
|
|
2627
|
+
return transform(self, typeSchema(self).pipe(between(minimum, maximum)), {
|
|
2628
|
+
strict: false,
|
|
2629
|
+
decode: i => number_.clamp(i, {
|
|
2630
|
+
minimum,
|
|
2631
|
+
maximum
|
|
2632
|
+
}),
|
|
2633
|
+
encode: identity
|
|
2634
|
+
});
|
|
2635
|
+
};
|
|
2600
2636
|
/**
|
|
2601
|
-
* Transforms a `string` into a `number` by parsing the string using the `parse`
|
|
2637
|
+
* Transforms a `string` into a `number` by parsing the string using the `parse`
|
|
2638
|
+
* function of the `effect/Number` module.
|
|
2602
2639
|
*
|
|
2603
|
-
* It returns an error if the value can't be converted (for example when
|
|
2640
|
+
* It returns an error if the value can't be converted (for example when
|
|
2641
|
+
* non-numeric characters are provided).
|
|
2604
2642
|
*
|
|
2605
|
-
* The following special string values are supported: "NaN", "Infinity",
|
|
2643
|
+
* The following special string values are supported: "NaN", "Infinity",
|
|
2644
|
+
* "-Infinity".
|
|
2606
2645
|
*
|
|
2607
2646
|
* @category number transformations
|
|
2608
2647
|
* @since 3.10.0
|
|
2609
2648
|
*/
|
|
2610
|
-
export
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2649
|
+
export function parseNumber(self) {
|
|
2650
|
+
return transformOrFail(self, Number$, {
|
|
2651
|
+
strict: false,
|
|
2652
|
+
decode: (i, _, ast) => ParseResult.fromOption(number_.parse(i), () => new ParseResult.Type(ast, i, `Unable to decode ${JSON.stringify(i)} into a number`)),
|
|
2653
|
+
encode: a => ParseResult.succeed(String(a))
|
|
2654
|
+
});
|
|
2655
|
+
}
|
|
2615
2656
|
/**
|
|
2616
2657
|
* This schema transforms a `string` into a `number` by parsing the string using the `parse` function of the `effect/Number` module.
|
|
2617
2658
|
*
|
|
@@ -2713,10 +2754,10 @@ export class Not extends /*#__PURE__*/transform( /*#__PURE__*/Boolean$.annotatio
|
|
|
2713
2754
|
description: "a boolean that will be negated"
|
|
2714
2755
|
}), Boolean$, {
|
|
2715
2756
|
strict: true,
|
|
2716
|
-
decode: boolean_.not,
|
|
2717
|
-
encode: boolean_.not
|
|
2757
|
+
decode: i => boolean_.not(i),
|
|
2758
|
+
encode: a => boolean_.not(a)
|
|
2718
2759
|
}) {}
|
|
2719
|
-
const encodeSymbol = (sym,
|
|
2760
|
+
const encodeSymbol = (sym, ast) => {
|
|
2720
2761
|
const key = Symbol.keyFor(sym);
|
|
2721
2762
|
return key === undefined ? ParseResult.fail(new ParseResult.Type(ast, sym, `Unable to encode a unique symbol ${String(sym)} into a string`)) : ParseResult.succeed(key);
|
|
2722
2763
|
};
|
|
@@ -2726,8 +2767,8 @@ class Symbol$ extends /*#__PURE__*/transformOrFail(String$.annotations({
|
|
|
2726
2767
|
description: "a string to be decoded into a globally shared symbol"
|
|
2727
2768
|
}), SymbolFromSelf, {
|
|
2728
2769
|
strict: false,
|
|
2729
|
-
decode: decodeSymbol,
|
|
2730
|
-
encode: encodeSymbol
|
|
2770
|
+
decode: i => decodeSymbol(i),
|
|
2771
|
+
encode: (a, _, ast) => encodeSymbol(a, ast)
|
|
2731
2772
|
}).annotations({
|
|
2732
2773
|
identifier: "Symbol"
|
|
2733
2774
|
}) {}
|
|
@@ -2739,20 +2780,6 @@ export {
|
|
|
2739
2780
|
* @since 3.10.0
|
|
2740
2781
|
*/
|
|
2741
2782
|
Symbol$ as Symbol };
|
|
2742
|
-
const SymbolStruct = /*#__PURE__*/TaggedStruct("symbol", {
|
|
2743
|
-
key: String$
|
|
2744
|
-
}).annotations({
|
|
2745
|
-
description: "an object to be decoded into a globally shared symbol"
|
|
2746
|
-
});
|
|
2747
|
-
const SymbolFromStruct = /*#__PURE__*/transformOrFail(SymbolStruct, SymbolFromSelf, {
|
|
2748
|
-
strict: true,
|
|
2749
|
-
decode: ({
|
|
2750
|
-
key
|
|
2751
|
-
}) => decodeSymbol(key),
|
|
2752
|
-
encode: (sym, _, ast) => ParseResult.map(encodeSymbol(sym, _, ast), key => SymbolStruct.make({
|
|
2753
|
-
key
|
|
2754
|
-
}))
|
|
2755
|
-
});
|
|
2756
2783
|
/**
|
|
2757
2784
|
* @category schema id
|
|
2758
2785
|
* @since 3.10.0
|
|
@@ -2884,7 +2911,7 @@ export const nonPositiveBigInt = annotations => lessThanOrEqualToBigInt(0n, {
|
|
|
2884
2911
|
*/
|
|
2885
2912
|
export const clampBigInt = (minimum, maximum) => self => transform(self, self.pipe(typeSchema, betweenBigInt(minimum, maximum)), {
|
|
2886
2913
|
strict: false,
|
|
2887
|
-
decode:
|
|
2914
|
+
decode: i => bigInt_.clamp(i, {
|
|
2888
2915
|
minimum,
|
|
2889
2916
|
maximum
|
|
2890
2917
|
}),
|
|
@@ -2895,8 +2922,8 @@ class BigInt$ extends /*#__PURE__*/transformOrFail(String$.annotations({
|
|
|
2895
2922
|
description: "a string to be decoded into a bigint"
|
|
2896
2923
|
}), BigIntFromSelf, {
|
|
2897
2924
|
strict: true,
|
|
2898
|
-
decode: (
|
|
2899
|
-
encode:
|
|
2925
|
+
decode: (i, _, ast) => ParseResult.fromOption(bigInt_.fromString(i), () => new ParseResult.Type(ast, i, `Unable to decode ${JSON.stringify(i)} into a bigint`)),
|
|
2926
|
+
encode: a => ParseResult.succeed(String(a))
|
|
2900
2927
|
}).annotations({
|
|
2901
2928
|
identifier: "BigInt"
|
|
2902
2929
|
}) {}
|
|
@@ -2978,8 +3005,8 @@ export class BigIntFromNumber extends /*#__PURE__*/transformOrFail(Number$.annot
|
|
|
2978
3005
|
description: "a number to be decoded into a bigint"
|
|
2979
3006
|
}), BigIntFromSelf.pipe(betweenBigInt(BigInt(Number.MIN_SAFE_INTEGER), BigInt(Number.MAX_SAFE_INTEGER))), {
|
|
2980
3007
|
strict: true,
|
|
2981
|
-
decode: (
|
|
2982
|
-
encode: (
|
|
3008
|
+
decode: (i, _, ast) => ParseResult.fromOption(bigInt_.fromNumber(i), () => new ParseResult.Type(ast, i, `Unable to decode ${i} into a bigint`)),
|
|
3009
|
+
encode: (a, _, ast) => ParseResult.fromOption(bigInt_.toNumber(a), () => new ParseResult.Type(ast, a, `Unable to encode ${a}n into a number`))
|
|
2983
3010
|
}).annotations({
|
|
2984
3011
|
identifier: "BigIntFromNumber"
|
|
2985
3012
|
}) {}
|
|
@@ -3003,18 +3030,19 @@ export const RedactedFromSelf = value => declare([value], {
|
|
|
3003
3030
|
equivalence: redacted_.getEquivalence
|
|
3004
3031
|
});
|
|
3005
3032
|
/**
|
|
3006
|
-
* A
|
|
3033
|
+
* A transformation that transform a `Schema<A, I, R>` into a
|
|
3034
|
+
* `RedactedFromSelf<A>`.
|
|
3007
3035
|
*
|
|
3008
3036
|
* @category Redacted transformations
|
|
3009
3037
|
* @since 3.10.0
|
|
3010
3038
|
*/
|
|
3011
|
-
export
|
|
3012
|
-
return transform(value, RedactedFromSelf(typeSchema(value)), {
|
|
3039
|
+
export function Redacted(value) {
|
|
3040
|
+
return transform(value, RedactedFromSelf(typeSchema(asSchema(value))), {
|
|
3013
3041
|
strict: true,
|
|
3014
|
-
decode:
|
|
3015
|
-
encode:
|
|
3042
|
+
decode: i => redacted_.make(i),
|
|
3043
|
+
encode: a => redacted_.value(a)
|
|
3016
3044
|
});
|
|
3017
|
-
}
|
|
3045
|
+
}
|
|
3018
3046
|
/**
|
|
3019
3047
|
* @category Duration constructors
|
|
3020
3048
|
* @since 3.10.0
|
|
@@ -3040,9 +3068,9 @@ export class DurationFromNanos extends /*#__PURE__*/transformOrFail(NonNegativeB
|
|
|
3040
3068
|
description: "a finite duration"
|
|
3041
3069
|
})), {
|
|
3042
3070
|
strict: true,
|
|
3043
|
-
decode:
|
|
3044
|
-
encode: (
|
|
3045
|
-
onNone: () => ParseResult.fail(new ParseResult.Type(ast,
|
|
3071
|
+
decode: i => ParseResult.succeed(duration_.nanos(i)),
|
|
3072
|
+
encode: (a, _, ast) => option_.match(duration_.toNanos(a), {
|
|
3073
|
+
onNone: () => ParseResult.fail(new ParseResult.Type(ast, a, `Unable to encode ${a} into a bigint`)),
|
|
3046
3074
|
onSome: nanos => ParseResult.succeed(nanos)
|
|
3047
3075
|
})
|
|
3048
3076
|
}).annotations({
|
|
@@ -3068,8 +3096,8 @@ export class DurationFromMillis extends /*#__PURE__*/transform(NonNegative.annot
|
|
|
3068
3096
|
description: "a non-negative number to be decoded into a Duration"
|
|
3069
3097
|
}), DurationFromSelf, {
|
|
3070
3098
|
strict: true,
|
|
3071
|
-
decode:
|
|
3072
|
-
encode:
|
|
3099
|
+
decode: i => duration_.millis(i),
|
|
3100
|
+
encode: a => duration_.toMillis(a)
|
|
3073
3101
|
}).annotations({
|
|
3074
3102
|
identifier: "DurationFromMillis"
|
|
3075
3103
|
}) {}
|
|
@@ -3109,29 +3137,29 @@ const isDurationValue = u => typeof u === "object";
|
|
|
3109
3137
|
*/
|
|
3110
3138
|
export class Duration extends /*#__PURE__*/transform(Union(DurationValue, HRTime), DurationFromSelf, {
|
|
3111
3139
|
strict: true,
|
|
3112
|
-
decode:
|
|
3113
|
-
if (isDurationValue(
|
|
3114
|
-
switch (
|
|
3140
|
+
decode: i => {
|
|
3141
|
+
if (isDurationValue(i)) {
|
|
3142
|
+
switch (i._tag) {
|
|
3115
3143
|
case "Millis":
|
|
3116
|
-
return duration_.millis(
|
|
3144
|
+
return duration_.millis(i.millis);
|
|
3117
3145
|
case "Nanos":
|
|
3118
|
-
return duration_.nanos(
|
|
3146
|
+
return duration_.nanos(i.nanos);
|
|
3119
3147
|
case "Infinity":
|
|
3120
3148
|
return duration_.infinity;
|
|
3121
3149
|
}
|
|
3122
3150
|
}
|
|
3123
|
-
const [seconds, nanos] =
|
|
3151
|
+
const [seconds, nanos] = i;
|
|
3124
3152
|
return seconds === -1 ? duration_.infinity : duration_.nanos(BigInt(seconds) * BigInt(1e9) + BigInt(nanos));
|
|
3125
3153
|
},
|
|
3126
|
-
encode:
|
|
3127
|
-
switch (
|
|
3154
|
+
encode: a => {
|
|
3155
|
+
switch (a.value._tag) {
|
|
3128
3156
|
case "Millis":
|
|
3129
3157
|
return DurationValueMillis.make({
|
|
3130
|
-
millis:
|
|
3158
|
+
millis: a.value.millis
|
|
3131
3159
|
});
|
|
3132
3160
|
case "Nanos":
|
|
3133
3161
|
return DurationValueNanos.make({
|
|
3134
|
-
nanos:
|
|
3162
|
+
nanos: a.value.nanos
|
|
3135
3163
|
});
|
|
3136
3164
|
case "Infinity":
|
|
3137
3165
|
return durationValueInfinity;
|
|
@@ -3148,7 +3176,7 @@ export class Duration extends /*#__PURE__*/transform(Union(DurationValue, HRTime
|
|
|
3148
3176
|
*/
|
|
3149
3177
|
export const clampDuration = (minimum, maximum) => self => transform(self, self.pipe(typeSchema, betweenDuration(minimum, maximum)), {
|
|
3150
3178
|
strict: false,
|
|
3151
|
-
decode:
|
|
3179
|
+
decode: i => duration_.clamp(i, {
|
|
3152
3180
|
minimum,
|
|
3153
3181
|
maximum
|
|
3154
3182
|
}),
|
|
@@ -3252,29 +3280,30 @@ export const betweenDuration = (minimum, maximum, annotations) => self => self.p
|
|
|
3252
3280
|
* @category Uint8Array constructors
|
|
3253
3281
|
* @since 3.10.0
|
|
3254
3282
|
*/
|
|
3255
|
-
export
|
|
3283
|
+
export class Uint8ArrayFromSelf extends /*#__PURE__*/declare(Predicate.isUint8Array, {
|
|
3256
3284
|
identifier: "Uint8ArrayFromSelf",
|
|
3257
3285
|
pretty: () => u8arr => `new Uint8Array(${JSON.stringify(Array.from(u8arr))})`,
|
|
3258
3286
|
arbitrary: () => fc => fc.uint8Array(),
|
|
3259
3287
|
equivalence: () => array_.getEquivalence(Equal.equals)
|
|
3260
|
-
})
|
|
3288
|
+
}) {}
|
|
3261
3289
|
/**
|
|
3262
3290
|
* @category number constructors
|
|
3263
3291
|
* @since 3.11.10
|
|
3264
3292
|
*/
|
|
3265
|
-
export
|
|
3293
|
+
export class Uint8 extends /*#__PURE__*/Number$.pipe( /*#__PURE__*/between(0, 255, {
|
|
3266
3294
|
identifier: "Uint8",
|
|
3267
3295
|
description: "a 8-bit unsigned integer"
|
|
3268
|
-
}))
|
|
3269
|
-
|
|
3296
|
+
})) {}
|
|
3297
|
+
/** @ignore */
|
|
3298
|
+
class Uint8Array$ extends /*#__PURE__*/transform(Array$(Uint8).annotations({
|
|
3270
3299
|
description: "an array of 8-bit unsigned integers to be decoded into a Uint8Array"
|
|
3271
3300
|
}), Uint8ArrayFromSelf, {
|
|
3272
3301
|
strict: true,
|
|
3273
|
-
decode:
|
|
3274
|
-
encode:
|
|
3302
|
+
decode: i => Uint8Array.from(i),
|
|
3303
|
+
encode: a => Array.from(a)
|
|
3275
3304
|
}).annotations({
|
|
3276
3305
|
identifier: "Uint8Array"
|
|
3277
|
-
})
|
|
3306
|
+
}) {}
|
|
3278
3307
|
export {
|
|
3279
3308
|
/**
|
|
3280
3309
|
* A schema that transforms an array of numbers into a `Uint8Array`.
|
|
@@ -3287,8 +3316,8 @@ const makeUint8ArrayTransformation = (id, decode, encode) => transformOrFail(Str
|
|
|
3287
3316
|
description: "a string to be decoded into a Uint8Array"
|
|
3288
3317
|
}), Uint8ArrayFromSelf, {
|
|
3289
3318
|
strict: true,
|
|
3290
|
-
decode: (
|
|
3291
|
-
encode:
|
|
3319
|
+
decode: (i, _, ast) => either_.mapLeft(decode(i), decodeException => new ParseResult.Type(ast, i, decodeException.message)),
|
|
3320
|
+
encode: a => ParseResult.succeed(encode(a))
|
|
3292
3321
|
}).annotations({
|
|
3293
3322
|
identifier: id
|
|
3294
3323
|
});
|
|
@@ -3317,8 +3346,8 @@ const makeEncodingTransformation = (id, decode, encode) => transformOrFail(Strin
|
|
|
3317
3346
|
description: `A string that is interpreted as being ${id}-encoded and will be decoded into a UTF-8 string`
|
|
3318
3347
|
}), String$, {
|
|
3319
3348
|
strict: true,
|
|
3320
|
-
decode: (
|
|
3321
|
-
encode:
|
|
3349
|
+
decode: (i, _, ast) => either_.mapLeft(decode(i), decodeException => new ParseResult.Type(ast, i, decodeException.message)),
|
|
3350
|
+
encode: a => ParseResult.succeed(encode(a))
|
|
3322
3351
|
}).annotations({
|
|
3323
3352
|
identifier: `StringFrom${id}`
|
|
3324
3353
|
});
|
|
@@ -3369,8 +3398,8 @@ export const StringFromUriComponent = /*#__PURE__*/transformOrFail(String$.annot
|
|
|
3369
3398
|
description: `A string that is interpreted as being UriComponent-encoded and will be decoded into a UTF-8 string`
|
|
3370
3399
|
}), String$, {
|
|
3371
3400
|
strict: true,
|
|
3372
|
-
decode: (
|
|
3373
|
-
encode: (
|
|
3401
|
+
decode: (i, _, ast) => either_.mapLeft(Encoding.decodeUriComponent(i), decodeException => new ParseResult.Type(ast, i, decodeException.message)),
|
|
3402
|
+
encode: (a, _, ast) => either_.mapLeft(Encoding.encodeUriComponent(a), encodeException => new ParseResult.Type(ast, a, encodeException.message))
|
|
3374
3403
|
}).annotations({
|
|
3375
3404
|
identifier: `StringFromUriComponent`
|
|
3376
3405
|
});
|
|
@@ -3461,25 +3490,29 @@ export const getNumberIndexedAccess = self => make(AST.getNumberIndexedAccess(se
|
|
|
3461
3490
|
* @category ReadonlyArray transformations
|
|
3462
3491
|
* @since 3.10.0
|
|
3463
3492
|
*/
|
|
3464
|
-
export
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
})
|
|
3493
|
+
export function head(self) {
|
|
3494
|
+
return transform(self, OptionFromSelf(getNumberIndexedAccess(typeSchema(self))), {
|
|
3495
|
+
strict: false,
|
|
3496
|
+
decode: i => array_.head(i),
|
|
3497
|
+
encode: a => option_.match(a, {
|
|
3498
|
+
onNone: () => [],
|
|
3499
|
+
onSome: array_.of
|
|
3500
|
+
})
|
|
3501
|
+
});
|
|
3502
|
+
}
|
|
3472
3503
|
/**
|
|
3473
3504
|
* Get the first element of a `NonEmptyReadonlyArray`.
|
|
3474
3505
|
*
|
|
3475
3506
|
* @category NonEmptyReadonlyArray transformations
|
|
3476
3507
|
* @since 3.12.0
|
|
3477
3508
|
*/
|
|
3478
|
-
export
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3509
|
+
export function headNonEmpty(self) {
|
|
3510
|
+
return transform(self, getNumberIndexedAccess(typeSchema(self)), {
|
|
3511
|
+
strict: false,
|
|
3512
|
+
decode: i => array_.headNonEmpty(i),
|
|
3513
|
+
encode: a => array_.of(a)
|
|
3514
|
+
});
|
|
3515
|
+
}
|
|
3483
3516
|
/**
|
|
3484
3517
|
* Retrieves the first element of a `ReadonlyArray`.
|
|
3485
3518
|
*
|
|
@@ -3490,7 +3523,7 @@ export const headNonEmpty = self => transform(self, getNumberIndexedAccess(typeS
|
|
|
3490
3523
|
*/
|
|
3491
3524
|
export const headOrElse = /*#__PURE__*/dual(args => isSchema(args[0]), (self, fallback) => transformOrFail(self, getNumberIndexedAccess(typeSchema(self)), {
|
|
3492
3525
|
strict: true,
|
|
3493
|
-
decode: (
|
|
3526
|
+
decode: (i, _, ast) => i.length > 0 ? ParseResult.succeed(i[0]) : fallback ? ParseResult.succeed(fallback()) : ParseResult.fail(new ParseResult.Type(ast, i, "Unable to retrieve the first element of an empty array")),
|
|
3494
3527
|
encode: a => ParseResult.succeed(array_.of(a))
|
|
3495
3528
|
}));
|
|
3496
3529
|
/**
|
|
@@ -3659,8 +3692,8 @@ export class DateFromString extends /*#__PURE__*/transform(String$.annotations({
|
|
|
3659
3692
|
description: "a string to be decoded into a Date"
|
|
3660
3693
|
}), DateFromSelf, {
|
|
3661
3694
|
strict: true,
|
|
3662
|
-
decode:
|
|
3663
|
-
encode:
|
|
3695
|
+
decode: i => new Date(i),
|
|
3696
|
+
encode: a => util_.formatDate(a)
|
|
3664
3697
|
}).annotations({
|
|
3665
3698
|
identifier: "DateFromString"
|
|
3666
3699
|
}) {}
|
|
@@ -3693,8 +3726,8 @@ export class DateFromNumber extends /*#__PURE__*/transform(Number$.annotations({
|
|
|
3693
3726
|
description: "a number to be decoded into a Date"
|
|
3694
3727
|
}), DateFromSelf, {
|
|
3695
3728
|
strict: true,
|
|
3696
|
-
decode:
|
|
3697
|
-
encode:
|
|
3729
|
+
decode: i => new Date(i),
|
|
3730
|
+
encode: a => a.getTime()
|
|
3698
3731
|
}).annotations({
|
|
3699
3732
|
identifier: "DateFromNumber"
|
|
3700
3733
|
}) {}
|
|
@@ -3713,7 +3746,7 @@ export class DateTimeUtcFromSelf extends /*#__PURE__*/declare(u => dateTime.isDa
|
|
|
3713
3746
|
}).map(date => dateTime.unsafeFromDate(date)),
|
|
3714
3747
|
equivalence: () => dateTime.Equivalence
|
|
3715
3748
|
}) {}
|
|
3716
|
-
const decodeDateTimeUtc = (input,
|
|
3749
|
+
const decodeDateTimeUtc = (input, ast) => ParseResult.try({
|
|
3717
3750
|
try: () => dateTime.unsafeMake(input),
|
|
3718
3751
|
catch: () => new ParseResult.Type(ast, input, `Unable to decode ${util_.formatUnknown(input)} into a DateTime.Utc`)
|
|
3719
3752
|
});
|
|
@@ -3727,8 +3760,8 @@ export class DateTimeUtcFromNumber extends /*#__PURE__*/transformOrFail(Number$.
|
|
|
3727
3760
|
description: "a number to be decoded into a DateTime.Utc"
|
|
3728
3761
|
}), DateTimeUtcFromSelf, {
|
|
3729
3762
|
strict: true,
|
|
3730
|
-
decode: decodeDateTimeUtc,
|
|
3731
|
-
encode:
|
|
3763
|
+
decode: (i, _, ast) => decodeDateTimeUtc(i, ast),
|
|
3764
|
+
encode: a => ParseResult.succeed(dateTime.toEpochMillis(a))
|
|
3732
3765
|
}).annotations({
|
|
3733
3766
|
identifier: "DateTimeUtcFromNumber"
|
|
3734
3767
|
}) {}
|
|
@@ -3742,8 +3775,8 @@ export class DateTimeUtcFromDate extends /*#__PURE__*/transformOrFail(DateFromSe
|
|
|
3742
3775
|
description: "a Date to be decoded into a DateTime.Utc"
|
|
3743
3776
|
}), DateTimeUtcFromSelf, {
|
|
3744
3777
|
strict: true,
|
|
3745
|
-
decode: decodeDateTimeUtc,
|
|
3746
|
-
encode:
|
|
3778
|
+
decode: (i, _, ast) => decodeDateTimeUtc(i, ast),
|
|
3779
|
+
encode: a => ParseResult.succeed(dateTime.toDateUtc(a))
|
|
3747
3780
|
}).annotations({
|
|
3748
3781
|
identifier: "DateTimeUtcFromDate"
|
|
3749
3782
|
}) {}
|
|
@@ -3757,8 +3790,8 @@ export class DateTimeUtc extends /*#__PURE__*/transformOrFail(String$.annotation
|
|
|
3757
3790
|
description: "a string to be decoded into a DateTime.Utc"
|
|
3758
3791
|
}), DateTimeUtcFromSelf, {
|
|
3759
3792
|
strict: true,
|
|
3760
|
-
decode: decodeDateTimeUtc,
|
|
3761
|
-
encode:
|
|
3793
|
+
decode: (i, _, ast) => decodeDateTimeUtc(i, ast),
|
|
3794
|
+
encode: a => ParseResult.succeed(dateTime.formatIso(a))
|
|
3762
3795
|
}).annotations({
|
|
3763
3796
|
identifier: "DateTimeUtc"
|
|
3764
3797
|
}) {}
|
|
@@ -3788,8 +3821,8 @@ export class TimeZoneOffset extends /*#__PURE__*/transform(Number$.annotations({
|
|
|
3788
3821
|
description: "a number to be decoded into a TimeZone.Offset"
|
|
3789
3822
|
}), TimeZoneOffsetFromSelf, {
|
|
3790
3823
|
strict: true,
|
|
3791
|
-
decode: dateTime.zoneMakeOffset,
|
|
3792
|
-
encode:
|
|
3824
|
+
decode: i => dateTime.zoneMakeOffset(i),
|
|
3825
|
+
encode: a => a.offset
|
|
3793
3826
|
}).annotations({
|
|
3794
3827
|
identifier: "TimeZoneOffset"
|
|
3795
3828
|
}) {}
|
|
@@ -3816,11 +3849,11 @@ export class TimeZoneNamed extends /*#__PURE__*/transformOrFail(String$.annotati
|
|
|
3816
3849
|
description: "a string to be decoded into a TimeZone.Named"
|
|
3817
3850
|
}), TimeZoneNamedFromSelf, {
|
|
3818
3851
|
strict: true,
|
|
3819
|
-
decode: (
|
|
3820
|
-
try: () => dateTime.zoneUnsafeMakeNamed(
|
|
3821
|
-
catch: () => new ParseResult.Type(ast,
|
|
3852
|
+
decode: (i, _, ast) => ParseResult.try({
|
|
3853
|
+
try: () => dateTime.zoneUnsafeMakeNamed(i),
|
|
3854
|
+
catch: () => new ParseResult.Type(ast, i, `Unable to decode ${JSON.stringify(i)} into a TimeZone.Named`)
|
|
3822
3855
|
}),
|
|
3823
|
-
encode:
|
|
3856
|
+
encode: a => ParseResult.succeed(a.id)
|
|
3824
3857
|
}).annotations({
|
|
3825
3858
|
identifier: "TimeZoneNamed"
|
|
3826
3859
|
}) {}
|
|
@@ -3839,11 +3872,11 @@ export class TimeZone extends /*#__PURE__*/transformOrFail(String$.annotations({
|
|
|
3839
3872
|
description: "a string to be decoded into a TimeZone"
|
|
3840
3873
|
}), TimeZoneFromSelf, {
|
|
3841
3874
|
strict: true,
|
|
3842
|
-
decode: (
|
|
3843
|
-
onNone: () => ParseResult.fail(new ParseResult.Type(ast,
|
|
3875
|
+
decode: (i, _, ast) => option_.match(dateTime.zoneFromString(i), {
|
|
3876
|
+
onNone: () => ParseResult.fail(new ParseResult.Type(ast, i, `Unable to decode ${JSON.stringify(i)} into a TimeZone`)),
|
|
3844
3877
|
onSome: ParseResult.succeed
|
|
3845
3878
|
}),
|
|
3846
|
-
encode:
|
|
3879
|
+
encode: a => ParseResult.succeed(dateTime.zoneToString(a))
|
|
3847
3880
|
}).annotations({
|
|
3848
3881
|
identifier: "TimeZone"
|
|
3849
3882
|
}) {}
|
|
@@ -3877,11 +3910,11 @@ export class DateTimeZoned extends /*#__PURE__*/transformOrFail(String$.annotati
|
|
|
3877
3910
|
description: "a string to be decoded into a DateTime.Zoned"
|
|
3878
3911
|
}), DateTimeZonedFromSelf, {
|
|
3879
3912
|
strict: true,
|
|
3880
|
-
decode: (
|
|
3881
|
-
onNone: () => ParseResult.fail(new ParseResult.Type(ast,
|
|
3913
|
+
decode: (i, _, ast) => option_.match(dateTime.makeZonedFromString(i), {
|
|
3914
|
+
onNone: () => ParseResult.fail(new ParseResult.Type(ast, i, `Unable to decode ${JSON.stringify(i)} into a DateTime.Zoned`)),
|
|
3882
3915
|
onSome: ParseResult.succeed
|
|
3883
3916
|
}),
|
|
3884
|
-
encode:
|
|
3917
|
+
encode: a => ParseResult.succeed(dateTime.formatIsoZoned(a))
|
|
3885
3918
|
}).annotations({
|
|
3886
3919
|
identifier: "DateTimeZoned"
|
|
3887
3920
|
}) {}
|
|
@@ -3937,53 +3970,51 @@ const makeSomeEncoded = value => ({
|
|
|
3937
3970
|
* @category Option transformations
|
|
3938
3971
|
* @since 3.10.0
|
|
3939
3972
|
*/
|
|
3940
|
-
export
|
|
3973
|
+
export function Option(value) {
|
|
3941
3974
|
const value_ = asSchema(value);
|
|
3942
|
-
|
|
3975
|
+
const out = transform(optionEncoded(value_), OptionFromSelf(typeSchema(value_)), {
|
|
3943
3976
|
strict: true,
|
|
3944
|
-
decode: optionDecode,
|
|
3945
|
-
encode: option_.match({
|
|
3977
|
+
decode: i => optionDecode(i),
|
|
3978
|
+
encode: a => option_.match(a, {
|
|
3946
3979
|
onNone: () => makeNoneEncoded,
|
|
3947
3980
|
onSome: makeSomeEncoded
|
|
3948
3981
|
})
|
|
3949
3982
|
});
|
|
3950
|
-
|
|
3983
|
+
return out;
|
|
3984
|
+
}
|
|
3951
3985
|
/**
|
|
3952
3986
|
* @category Option transformations
|
|
3953
3987
|
* @since 3.10.0
|
|
3954
3988
|
*/
|
|
3955
|
-
export
|
|
3956
|
-
|
|
3957
|
-
return transform(NullOr(value_), OptionFromSelf(typeSchema(value_)), {
|
|
3989
|
+
export function OptionFromNullOr(value) {
|
|
3990
|
+
return transform(NullOr(value), OptionFromSelf(typeSchema(asSchema(value))), {
|
|
3958
3991
|
strict: true,
|
|
3959
|
-
decode: option_.fromNullable,
|
|
3960
|
-
encode: option_.getOrNull
|
|
3992
|
+
decode: i => option_.fromNullable(i),
|
|
3993
|
+
encode: a => option_.getOrNull(a)
|
|
3961
3994
|
});
|
|
3962
|
-
}
|
|
3995
|
+
}
|
|
3963
3996
|
/**
|
|
3964
3997
|
* @category Option transformations
|
|
3965
3998
|
* @since 3.10.0
|
|
3966
3999
|
*/
|
|
3967
|
-
export
|
|
3968
|
-
|
|
3969
|
-
return transform(NullishOr(value_), OptionFromSelf(typeSchema(value_)), {
|
|
4000
|
+
export function OptionFromNullishOr(value, onNoneEncoding) {
|
|
4001
|
+
return transform(NullishOr(value), OptionFromSelf(typeSchema(asSchema(value))), {
|
|
3970
4002
|
strict: true,
|
|
3971
|
-
decode: option_.fromNullable,
|
|
3972
|
-
encode: onNoneEncoding === null ? option_.getOrNull : option_.getOrUndefined
|
|
4003
|
+
decode: i => option_.fromNullable(i),
|
|
4004
|
+
encode: onNoneEncoding === null ? a => option_.getOrNull(a) : a => option_.getOrUndefined(a)
|
|
3973
4005
|
});
|
|
3974
|
-
}
|
|
4006
|
+
}
|
|
3975
4007
|
/**
|
|
3976
4008
|
* @category Option transformations
|
|
3977
4009
|
* @since 3.10.0
|
|
3978
4010
|
*/
|
|
3979
|
-
export
|
|
3980
|
-
|
|
3981
|
-
return transform(UndefinedOr(value_), OptionFromSelf(typeSchema(value_)), {
|
|
4011
|
+
export function OptionFromUndefinedOr(value) {
|
|
4012
|
+
return transform(UndefinedOr(value), OptionFromSelf(typeSchema(asSchema(value))), {
|
|
3982
4013
|
strict: true,
|
|
3983
|
-
decode: option_.fromNullable,
|
|
3984
|
-
encode: option_.getOrUndefined
|
|
4014
|
+
decode: i => option_.fromNullable(i),
|
|
4015
|
+
encode: a => option_.getOrUndefined(a)
|
|
3985
4016
|
});
|
|
3986
|
-
}
|
|
4017
|
+
}
|
|
3987
4018
|
/**
|
|
3988
4019
|
* Transforms strings into an Option type, effectively filtering out empty or
|
|
3989
4020
|
* whitespace-only strings by trimming them and checking their length. Returns
|
|
@@ -4001,11 +4032,11 @@ export const OptionFromUndefinedOr = value => {
|
|
|
4001
4032
|
* @category Option transformations
|
|
4002
4033
|
* @since 3.10.0
|
|
4003
4034
|
*/
|
|
4004
|
-
export
|
|
4035
|
+
export class OptionFromNonEmptyTrimmedString extends /*#__PURE__*/transform(String$, /*#__PURE__*/OptionFromSelf(NonEmptyTrimmedString), {
|
|
4005
4036
|
strict: true,
|
|
4006
|
-
decode:
|
|
4007
|
-
encode:
|
|
4008
|
-
})
|
|
4037
|
+
decode: i => option_.filter(option_.some(i.trim()), string_.isNonEmpty),
|
|
4038
|
+
encode: a => option_.getOrElse(a, () => "")
|
|
4039
|
+
}) {}
|
|
4009
4040
|
const rightEncoded = right => Struct({
|
|
4010
4041
|
_tag: Literal("Right"),
|
|
4011
4042
|
right
|
|
@@ -4076,17 +4107,18 @@ export const Either = ({
|
|
|
4076
4107
|
}) => {
|
|
4077
4108
|
const right_ = asSchema(right);
|
|
4078
4109
|
const left_ = asSchema(left);
|
|
4079
|
-
|
|
4110
|
+
const out = transform(eitherEncoded(right_, left_), EitherFromSelf({
|
|
4080
4111
|
left: typeSchema(left_),
|
|
4081
4112
|
right: typeSchema(right_)
|
|
4082
4113
|
}), {
|
|
4083
4114
|
strict: true,
|
|
4084
|
-
decode: eitherDecode,
|
|
4085
|
-
encode: either_.match({
|
|
4115
|
+
decode: i => eitherDecode(i),
|
|
4116
|
+
encode: a => either_.match(a, {
|
|
4086
4117
|
onLeft: makeLeftEncoded,
|
|
4087
4118
|
onRight: makeRightEncoded
|
|
4088
4119
|
})
|
|
4089
4120
|
});
|
|
4121
|
+
return out;
|
|
4090
4122
|
};
|
|
4091
4123
|
/**
|
|
4092
4124
|
* @example
|
|
@@ -4110,25 +4142,26 @@ export const EitherFromUnion = ({
|
|
|
4110
4142
|
const toleft = typeSchema(left_);
|
|
4111
4143
|
const fromRight = transform(right_, rightEncoded(toright), {
|
|
4112
4144
|
strict: true,
|
|
4113
|
-
decode: makeRightEncoded,
|
|
4114
|
-
encode:
|
|
4145
|
+
decode: i => makeRightEncoded(i),
|
|
4146
|
+
encode: a => a.right
|
|
4115
4147
|
});
|
|
4116
4148
|
const fromLeft = transform(left_, leftEncoded(toleft), {
|
|
4117
4149
|
strict: true,
|
|
4118
|
-
decode: makeLeftEncoded,
|
|
4119
|
-
encode:
|
|
4150
|
+
decode: i => makeLeftEncoded(i),
|
|
4151
|
+
encode: a => a.left
|
|
4120
4152
|
});
|
|
4121
|
-
|
|
4153
|
+
const out = transform(Union(fromRight, fromLeft), EitherFromSelf({
|
|
4122
4154
|
left: toleft,
|
|
4123
4155
|
right: toright
|
|
4124
4156
|
}), {
|
|
4125
4157
|
strict: true,
|
|
4126
|
-
decode:
|
|
4127
|
-
encode: either_.match({
|
|
4158
|
+
decode: i => i._tag === "Left" ? either_.left(i.left) : either_.right(i.right),
|
|
4159
|
+
encode: a => either_.match(a, {
|
|
4128
4160
|
onLeft: makeLeftEncoded,
|
|
4129
4161
|
onRight: makeRightEncoded
|
|
4130
4162
|
})
|
|
4131
4163
|
});
|
|
4164
|
+
return out;
|
|
4132
4165
|
};
|
|
4133
4166
|
const mapArbitrary = (key, value, ctx) => {
|
|
4134
4167
|
return fc => {
|
|
@@ -4171,36 +4204,33 @@ export const MapFromSelf = ({
|
|
|
4171
4204
|
* @category ReadonlyMap transformations
|
|
4172
4205
|
* @since 3.10.0
|
|
4173
4206
|
*/
|
|
4174
|
-
export
|
|
4207
|
+
export function ReadonlyMap({
|
|
4175
4208
|
key,
|
|
4176
4209
|
value
|
|
4177
|
-
})
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
key: typeSchema(key_),
|
|
4182
|
-
value: typeSchema(value_)
|
|
4210
|
+
}) {
|
|
4211
|
+
return transform(Array$(Tuple(key, value)), ReadonlyMapFromSelf({
|
|
4212
|
+
key: typeSchema(asSchema(key)),
|
|
4213
|
+
value: typeSchema(asSchema(value))
|
|
4183
4214
|
}), {
|
|
4184
4215
|
strict: true,
|
|
4185
|
-
decode:
|
|
4186
|
-
encode:
|
|
4216
|
+
decode: i => new Map(i),
|
|
4217
|
+
encode: a => Array.from(a.entries())
|
|
4187
4218
|
});
|
|
4188
|
-
}
|
|
4189
|
-
|
|
4219
|
+
}
|
|
4220
|
+
/** @ignore */
|
|
4221
|
+
function map({
|
|
4190
4222
|
key,
|
|
4191
4223
|
value
|
|
4192
|
-
})
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
key: typeSchema(key_),
|
|
4197
|
-
value: typeSchema(value_)
|
|
4224
|
+
}) {
|
|
4225
|
+
return transform(Array$(Tuple(key, value)), MapFromSelf({
|
|
4226
|
+
key: typeSchema(asSchema(key)),
|
|
4227
|
+
value: typeSchema(asSchema(value))
|
|
4198
4228
|
}), {
|
|
4199
4229
|
strict: true,
|
|
4200
|
-
decode:
|
|
4201
|
-
encode:
|
|
4230
|
+
decode: i => new Map(i),
|
|
4231
|
+
encode: a => Array.from(a.entries())
|
|
4202
4232
|
});
|
|
4203
|
-
}
|
|
4233
|
+
}
|
|
4204
4234
|
export {
|
|
4205
4235
|
/**
|
|
4206
4236
|
* @category Map transformations
|
|
@@ -4224,8 +4254,8 @@ export const ReadonlyMapFromRecord = ({
|
|
|
4224
4254
|
value: typeSchema(value)
|
|
4225
4255
|
}), {
|
|
4226
4256
|
strict: true,
|
|
4227
|
-
decode:
|
|
4228
|
-
encode:
|
|
4257
|
+
decode: i => new Map(Object.entries(i)),
|
|
4258
|
+
encode: a => Object.fromEntries(a)
|
|
4229
4259
|
});
|
|
4230
4260
|
/**
|
|
4231
4261
|
* @category Map transformations
|
|
@@ -4244,8 +4274,8 @@ export const MapFromRecord = ({
|
|
|
4244
4274
|
value: typeSchema(value)
|
|
4245
4275
|
}), {
|
|
4246
4276
|
strict: true,
|
|
4247
|
-
decode:
|
|
4248
|
-
encode:
|
|
4277
|
+
decode: i => new Map(Object.entries(i)),
|
|
4278
|
+
encode: a => Object.fromEntries(a)
|
|
4249
4279
|
});
|
|
4250
4280
|
const setArbitrary = (item, ctx) => fc => {
|
|
4251
4281
|
const items = fc.array(item(fc));
|
|
@@ -4280,22 +4310,21 @@ export const SetFromSelf = value => setFromSelf_(value, `Set<${format(value)}>`)
|
|
|
4280
4310
|
* @category ReadonlySet transformations
|
|
4281
4311
|
* @since 3.10.0
|
|
4282
4312
|
*/
|
|
4283
|
-
export
|
|
4284
|
-
|
|
4285
|
-
return transform(Array$(value_), ReadonlySetFromSelf(typeSchema(value_)), {
|
|
4313
|
+
export function ReadonlySet(value) {
|
|
4314
|
+
return transform(Array$(value), ReadonlySetFromSelf(typeSchema(asSchema(value))), {
|
|
4286
4315
|
strict: true,
|
|
4287
|
-
decode:
|
|
4288
|
-
encode:
|
|
4316
|
+
decode: i => new Set(i),
|
|
4317
|
+
encode: a => Array.from(a)
|
|
4289
4318
|
});
|
|
4290
|
-
}
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
return transform(Array$(
|
|
4319
|
+
}
|
|
4320
|
+
/** @ignore */
|
|
4321
|
+
function set(value) {
|
|
4322
|
+
return transform(Array$(value), SetFromSelf(typeSchema(asSchema(value))), {
|
|
4294
4323
|
strict: true,
|
|
4295
|
-
decode:
|
|
4296
|
-
encode:
|
|
4324
|
+
decode: i => new Set(i),
|
|
4325
|
+
encode: a => Array.from(a)
|
|
4297
4326
|
});
|
|
4298
|
-
}
|
|
4327
|
+
}
|
|
4299
4328
|
export {
|
|
4300
4329
|
/**
|
|
4301
4330
|
* @category Set transformations
|
|
@@ -4325,11 +4354,11 @@ export class BigDecimal extends /*#__PURE__*/transformOrFail(String$.annotations
|
|
|
4325
4354
|
description: "a string to be decoded into a BigDecimal"
|
|
4326
4355
|
}), BigDecimalFromSelf, {
|
|
4327
4356
|
strict: true,
|
|
4328
|
-
decode: (
|
|
4329
|
-
onNone: () => ParseResult.fail(new ParseResult.Type(ast,
|
|
4357
|
+
decode: (i, _, ast) => bigDecimal_.fromString(i).pipe(option_.match({
|
|
4358
|
+
onNone: () => ParseResult.fail(new ParseResult.Type(ast, i, `Unable to decode ${JSON.stringify(i)} into a BigDecimal`)),
|
|
4330
4359
|
onSome: val => ParseResult.succeed(bigDecimal_.normalize(val))
|
|
4331
4360
|
})),
|
|
4332
|
-
encode:
|
|
4361
|
+
encode: a => ParseResult.succeed(bigDecimal_.format(bigDecimal_.normalize(a)))
|
|
4333
4362
|
}).annotations({
|
|
4334
4363
|
identifier: "BigDecimal"
|
|
4335
4364
|
}) {}
|
|
@@ -4344,8 +4373,8 @@ export class BigDecimalFromNumber extends /*#__PURE__*/transform(Number$.annotat
|
|
|
4344
4373
|
description: "a number to be decoded into a BigDecimal"
|
|
4345
4374
|
}), BigDecimalFromSelf, {
|
|
4346
4375
|
strict: true,
|
|
4347
|
-
decode: bigDecimal_.unsafeFromNumber,
|
|
4348
|
-
encode: bigDecimal_.unsafeToNumber
|
|
4376
|
+
decode: i => bigDecimal_.unsafeFromNumber(i),
|
|
4377
|
+
encode: a => bigDecimal_.unsafeToNumber(a)
|
|
4349
4378
|
}).annotations({
|
|
4350
4379
|
identifier: "BigDecimalFromNumber"
|
|
4351
4380
|
}) {}
|
|
@@ -4555,7 +4584,7 @@ export const betweenBigDecimal = (minimum, maximum, annotations) => self => {
|
|
|
4555
4584
|
*/
|
|
4556
4585
|
export const clampBigDecimal = (minimum, maximum) => self => transform(self, self.pipe(typeSchema, betweenBigDecimal(minimum, maximum)), {
|
|
4557
4586
|
strict: false,
|
|
4558
|
-
decode:
|
|
4587
|
+
decode: i => bigDecimal_.clamp(i, {
|
|
4559
4588
|
minimum,
|
|
4560
4589
|
maximum
|
|
4561
4590
|
}),
|
|
@@ -4586,14 +4615,13 @@ export const ChunkFromSelf = value => {
|
|
|
4586
4615
|
* @category Chunk transformations
|
|
4587
4616
|
* @since 3.10.0
|
|
4588
4617
|
*/
|
|
4589
|
-
export
|
|
4590
|
-
|
|
4591
|
-
return transform(Array$(value_), ChunkFromSelf(typeSchema(value_)), {
|
|
4618
|
+
export function Chunk(value) {
|
|
4619
|
+
return transform(Array$(value), ChunkFromSelf(typeSchema(asSchema(value))), {
|
|
4592
4620
|
strict: true,
|
|
4593
|
-
decode:
|
|
4594
|
-
encode: chunk_.toReadonlyArray
|
|
4621
|
+
decode: i => i.length === 0 ? chunk_.empty() : chunk_.fromIterable(i),
|
|
4622
|
+
encode: a => chunk_.toReadonlyArray(a)
|
|
4595
4623
|
});
|
|
4596
|
-
}
|
|
4624
|
+
}
|
|
4597
4625
|
const nonEmptyChunkArbitrary = item => fc => fastCheck_.array(item(fc), {
|
|
4598
4626
|
minLength: 1
|
|
4599
4627
|
}).map(as => chunk_.unsafeFromNonEmptyArray(as));
|
|
@@ -4618,39 +4646,48 @@ export const NonEmptyChunkFromSelf = value => {
|
|
|
4618
4646
|
* @category Chunk transformations
|
|
4619
4647
|
* @since 3.10.0
|
|
4620
4648
|
*/
|
|
4621
|
-
export
|
|
4622
|
-
|
|
4623
|
-
return transform(NonEmptyArray(value_), NonEmptyChunkFromSelf(typeSchema(value_)), {
|
|
4649
|
+
export function NonEmptyChunk(value) {
|
|
4650
|
+
return transform(NonEmptyArray(value), NonEmptyChunkFromSelf(typeSchema(asSchema(value))), {
|
|
4624
4651
|
strict: true,
|
|
4625
|
-
decode: chunk_.unsafeFromNonEmptyArray,
|
|
4626
|
-
encode: chunk_.toReadonlyArray
|
|
4652
|
+
decode: i => chunk_.unsafeFromNonEmptyArray(i),
|
|
4653
|
+
encode: a => chunk_.toReadonlyArray(a)
|
|
4627
4654
|
});
|
|
4628
|
-
}
|
|
4629
|
-
const
|
|
4630
|
-
const dataArbitrary = item => fc => item(fc).map(
|
|
4655
|
+
}
|
|
4656
|
+
const decodeData = a => Array.isArray(a) ? data_.array(a) : data_.struct(a);
|
|
4657
|
+
const dataArbitrary = item => fc => item(fc).map(decodeData);
|
|
4631
4658
|
const dataPretty = item => d => `Data(${item(d)})`;
|
|
4632
|
-
const dataParse = decodeUnknown => (u, options, ast) => Equal.isEqual(u) ? toComposite(decodeUnknown(u, options),
|
|
4659
|
+
const dataParse = decodeUnknown => (u, options, ast) => Equal.isEqual(u) ? toComposite(decodeUnknown(u, options), decodeData, ast, u) : ParseResult.fail(new ParseResult.Type(ast, u));
|
|
4633
4660
|
/**
|
|
4661
|
+
* Type and Encoded must extend `Readonly<Record<string, any>> |
|
|
4662
|
+
* ReadonlyArray<any>` to be compatible with this API.
|
|
4663
|
+
*
|
|
4634
4664
|
* @category Data transformations
|
|
4635
4665
|
* @since 3.10.0
|
|
4636
4666
|
*/
|
|
4637
|
-
export const DataFromSelf =
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4667
|
+
export const DataFromSelf = value => {
|
|
4668
|
+
return declare([value], {
|
|
4669
|
+
decode: item => dataParse(ParseResult.decodeUnknown(item)),
|
|
4670
|
+
encode: item => dataParse(ParseResult.encodeUnknown(item))
|
|
4671
|
+
}, {
|
|
4672
|
+
description: `Data<${format(value)}>`,
|
|
4673
|
+
pretty: dataPretty,
|
|
4674
|
+
arbitrary: dataArbitrary
|
|
4675
|
+
});
|
|
4676
|
+
};
|
|
4645
4677
|
/**
|
|
4678
|
+
* Type and Encoded must extend `Readonly<Record<string, any>> |
|
|
4679
|
+
* ReadonlyArray<any>` to be compatible with this API.
|
|
4680
|
+
*
|
|
4646
4681
|
* @category Data transformations
|
|
4647
4682
|
* @since 3.10.0
|
|
4648
4683
|
*/
|
|
4649
|
-
export const Data =
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
})
|
|
4684
|
+
export const Data = value => {
|
|
4685
|
+
return transform(value, DataFromSelf(typeSchema(value)), {
|
|
4686
|
+
strict: false,
|
|
4687
|
+
decode: i => decodeData(i),
|
|
4688
|
+
encode: a => Array.isArray(a) ? Array.from(a) : Object.assign({}, a)
|
|
4689
|
+
});
|
|
4690
|
+
};
|
|
4654
4691
|
const isField = u => isSchema(u) || isPropertySignature(u);
|
|
4655
4692
|
const isFields = fields => util_.ownKeys(fields).every(key => isField(fields[key]));
|
|
4656
4693
|
const getFields = hasFields => "fields" in hasFields ? hasFields.fields : getFields(hasFields[RefineSchemaId]);
|
|
@@ -4857,7 +4894,7 @@ const makeClass = ({
|
|
|
4857
4894
|
});
|
|
4858
4895
|
out = transform(encodedSide, declaration, {
|
|
4859
4896
|
strict: true,
|
|
4860
|
-
decode:
|
|
4897
|
+
decode: i => new this(i, true),
|
|
4861
4898
|
encode: identity
|
|
4862
4899
|
}).annotations({
|
|
4863
4900
|
[AST.SurrogateAnnotationId]: transformationSurrogate.ast,
|
|
@@ -5036,8 +5073,8 @@ const fiberIdEncode = input => {
|
|
|
5036
5073
|
*/
|
|
5037
5074
|
export class FiberId extends /*#__PURE__*/transform(FiberIdEncoded, FiberIdFromSelf, {
|
|
5038
5075
|
strict: true,
|
|
5039
|
-
decode: fiberIdDecode,
|
|
5040
|
-
encode: fiberIdEncode
|
|
5076
|
+
decode: i => fiberIdDecode(i),
|
|
5077
|
+
encode: a => fiberIdEncode(a)
|
|
5041
5078
|
}).annotations({
|
|
5042
5079
|
identifier: "FiberId"
|
|
5043
5080
|
}) {}
|
|
@@ -5056,19 +5093,19 @@ const CauseInterruptEncoded = /*#__PURE__*/Struct({
|
|
|
5056
5093
|
_tag: /*#__PURE__*/Literal("Interrupt"),
|
|
5057
5094
|
fiberId: FiberIdEncoded
|
|
5058
5095
|
});
|
|
5059
|
-
const causeParallelEncoded = causeEncoded => Struct({
|
|
5060
|
-
_tag: Literal("Parallel"),
|
|
5061
|
-
left: causeEncoded,
|
|
5062
|
-
right: causeEncoded
|
|
5063
|
-
});
|
|
5064
|
-
const causeSequentialEncoded = causeEncoded => Struct({
|
|
5065
|
-
_tag: Literal("Sequential"),
|
|
5066
|
-
left: causeEncoded,
|
|
5067
|
-
right: causeEncoded
|
|
5068
|
-
});
|
|
5069
5096
|
const causeEncoded = (error, defect) => {
|
|
5070
|
-
const
|
|
5071
|
-
const
|
|
5097
|
+
const error_ = asSchema(error);
|
|
5098
|
+
const defect_ = asSchema(defect);
|
|
5099
|
+
const suspended = suspend(() => out);
|
|
5100
|
+
const out = Union(CauseEmptyEncoded, causeFailEncoded(error_), causeDieEncoded(defect_), CauseInterruptEncoded, Struct({
|
|
5101
|
+
_tag: Literal("Sequential"),
|
|
5102
|
+
left: suspended,
|
|
5103
|
+
right: suspended
|
|
5104
|
+
}), Struct({
|
|
5105
|
+
_tag: Literal("Parallel"),
|
|
5106
|
+
left: suspended,
|
|
5107
|
+
right: suspended
|
|
5108
|
+
})).annotations({
|
|
5072
5109
|
title: `CauseEncoded<${format(error)}>`
|
|
5073
5110
|
});
|
|
5074
5111
|
return out;
|
|
@@ -5199,14 +5236,15 @@ export const Cause = ({
|
|
|
5199
5236
|
}) => {
|
|
5200
5237
|
const error_ = asSchema(error);
|
|
5201
5238
|
const defect_ = asSchema(defect);
|
|
5202
|
-
|
|
5239
|
+
const out = transform(causeEncoded(error_, defect_), CauseFromSelf({
|
|
5203
5240
|
error: typeSchema(error_),
|
|
5204
|
-
defect:
|
|
5241
|
+
defect: typeSchema(defect_)
|
|
5205
5242
|
}), {
|
|
5206
5243
|
strict: false,
|
|
5207
|
-
decode: causeDecode,
|
|
5208
|
-
encode: causeEncode
|
|
5244
|
+
decode: i => causeDecode(i),
|
|
5245
|
+
encode: a => causeEncode(a)
|
|
5209
5246
|
});
|
|
5247
|
+
return out;
|
|
5210
5248
|
};
|
|
5211
5249
|
/**
|
|
5212
5250
|
* Defines a schema for handling JavaScript errors (`Error` instances) and other types of defects.
|
|
@@ -5221,34 +5259,34 @@ export const Cause = ({
|
|
|
5221
5259
|
* @category defect
|
|
5222
5260
|
* @since 3.10.0
|
|
5223
5261
|
*/
|
|
5224
|
-
export
|
|
5262
|
+
export class Defect extends /*#__PURE__*/transform(Unknown, Unknown, {
|
|
5225
5263
|
strict: true,
|
|
5226
|
-
decode:
|
|
5227
|
-
if (Predicate.isObject(
|
|
5228
|
-
const err = new Error(
|
|
5229
|
-
cause:
|
|
5264
|
+
decode: i => {
|
|
5265
|
+
if (Predicate.isObject(i) && "message" in i && typeof i.message === "string") {
|
|
5266
|
+
const err = new Error(i.message, {
|
|
5267
|
+
cause: i
|
|
5230
5268
|
});
|
|
5231
|
-
if ("name" in
|
|
5232
|
-
err.name =
|
|
5269
|
+
if ("name" in i && typeof i.name === "string") {
|
|
5270
|
+
err.name = i.name;
|
|
5233
5271
|
}
|
|
5234
|
-
err.stack = "stack" in
|
|
5272
|
+
err.stack = "stack" in i && typeof i.stack === "string" ? i.stack : "";
|
|
5235
5273
|
return err;
|
|
5236
5274
|
}
|
|
5237
|
-
return String(
|
|
5275
|
+
return String(i);
|
|
5238
5276
|
},
|
|
5239
|
-
encode:
|
|
5240
|
-
if (
|
|
5277
|
+
encode: a => {
|
|
5278
|
+
if (a instanceof Error) {
|
|
5241
5279
|
return {
|
|
5242
|
-
name:
|
|
5243
|
-
message:
|
|
5280
|
+
name: a.name,
|
|
5281
|
+
message: a.message
|
|
5244
5282
|
// no stack because of security reasons
|
|
5245
5283
|
};
|
|
5246
5284
|
}
|
|
5247
|
-
return internalCause_.prettyErrorMessage(
|
|
5285
|
+
return internalCause_.prettyErrorMessage(a);
|
|
5248
5286
|
}
|
|
5249
5287
|
}).annotations({
|
|
5250
5288
|
identifier: "Defect"
|
|
5251
|
-
})
|
|
5289
|
+
}) {}
|
|
5252
5290
|
const exitFailureEncoded = (error, defect) => Struct({
|
|
5253
5291
|
_tag: Literal("Failure"),
|
|
5254
5292
|
cause: causeEncoded(error, defect)
|
|
@@ -5257,9 +5295,11 @@ const exitSuccessEncoded = value => Struct({
|
|
|
5257
5295
|
_tag: Literal("Success"),
|
|
5258
5296
|
value
|
|
5259
5297
|
});
|
|
5260
|
-
const exitEncoded = (value, error, defect) =>
|
|
5261
|
-
|
|
5262
|
-
})
|
|
5298
|
+
const exitEncoded = (value, error, defect) => {
|
|
5299
|
+
return Union(exitFailureEncoded(error, defect), exitSuccessEncoded(value)).annotations({
|
|
5300
|
+
title: `ExitEncoded<${format(value)}, ${format(error)}, ${format(defect)}>`
|
|
5301
|
+
});
|
|
5302
|
+
};
|
|
5263
5303
|
const exitDecode = input => {
|
|
5264
5304
|
switch (input._tag) {
|
|
5265
5305
|
case "Failure":
|
|
@@ -5314,21 +5354,22 @@ export const Exit = ({
|
|
|
5314
5354
|
const success_ = asSchema(success);
|
|
5315
5355
|
const failure_ = asSchema(failure);
|
|
5316
5356
|
const defect_ = asSchema(defect);
|
|
5317
|
-
|
|
5357
|
+
const out = transform(exitEncoded(success_, failure_, defect_), ExitFromSelf({
|
|
5318
5358
|
failure: typeSchema(failure_),
|
|
5319
5359
|
success: typeSchema(success_),
|
|
5320
|
-
defect:
|
|
5360
|
+
defect: typeSchema(defect_)
|
|
5321
5361
|
}), {
|
|
5322
5362
|
strict: false,
|
|
5323
|
-
decode: exitDecode,
|
|
5324
|
-
encode:
|
|
5363
|
+
decode: i => exitDecode(i),
|
|
5364
|
+
encode: a => a._tag === "Failure" ? {
|
|
5325
5365
|
_tag: "Failure",
|
|
5326
|
-
cause:
|
|
5366
|
+
cause: a.cause
|
|
5327
5367
|
} : {
|
|
5328
5368
|
_tag: "Success",
|
|
5329
|
-
value:
|
|
5369
|
+
value: a.value
|
|
5330
5370
|
}
|
|
5331
5371
|
});
|
|
5372
|
+
return out;
|
|
5332
5373
|
};
|
|
5333
5374
|
const hashSetArbitrary = (item, ctx) => fc => {
|
|
5334
5375
|
const items = fc.array(item(fc));
|
|
@@ -5359,14 +5400,13 @@ export const HashSetFromSelf = value => {
|
|
|
5359
5400
|
* @category HashSet transformations
|
|
5360
5401
|
* @since 3.10.0
|
|
5361
5402
|
*/
|
|
5362
|
-
export
|
|
5363
|
-
|
|
5364
|
-
return transform(Array$(value_), HashSetFromSelf(typeSchema(value_)), {
|
|
5403
|
+
export function HashSet(value) {
|
|
5404
|
+
return transform(Array$(value), HashSetFromSelf(typeSchema(asSchema(value))), {
|
|
5365
5405
|
strict: true,
|
|
5366
|
-
decode:
|
|
5367
|
-
encode:
|
|
5406
|
+
decode: i => hashSet_.fromIterable(i),
|
|
5407
|
+
encode: a => Array.from(a)
|
|
5368
5408
|
});
|
|
5369
|
-
}
|
|
5409
|
+
}
|
|
5370
5410
|
const hashMapArbitrary = (key, value, ctx) => fc => {
|
|
5371
5411
|
const items = fc.array(fc.tuple(key(fc), value(fc)));
|
|
5372
5412
|
return (ctx.depthIdentifier !== undefined ? fc.oneof(ctx, fc.constant([]), items) : items).map(hashMap_.fromIterable);
|
|
@@ -5403,15 +5443,13 @@ export const HashMap = ({
|
|
|
5403
5443
|
key,
|
|
5404
5444
|
value
|
|
5405
5445
|
}) => {
|
|
5406
|
-
|
|
5407
|
-
|
|
5408
|
-
|
|
5409
|
-
key: typeSchema(key_),
|
|
5410
|
-
value: typeSchema(value_)
|
|
5446
|
+
return transform(Array$(Tuple(key, value)), HashMapFromSelf({
|
|
5447
|
+
key: typeSchema(asSchema(key)),
|
|
5448
|
+
value: typeSchema(asSchema(value))
|
|
5411
5449
|
}), {
|
|
5412
5450
|
strict: true,
|
|
5413
|
-
decode:
|
|
5414
|
-
encode:
|
|
5451
|
+
decode: i => hashMap_.fromIterable(i),
|
|
5452
|
+
encode: a => Array.from(a)
|
|
5415
5453
|
});
|
|
5416
5454
|
};
|
|
5417
5455
|
const listArbitrary = (item, ctx) => fc => {
|
|
@@ -5443,14 +5481,13 @@ export const ListFromSelf = value => {
|
|
|
5443
5481
|
* @category List transformations
|
|
5444
5482
|
* @since 3.10.0
|
|
5445
5483
|
*/
|
|
5446
|
-
export
|
|
5447
|
-
|
|
5448
|
-
return transform(Array$(value_), ListFromSelf(typeSchema(value_)), {
|
|
5484
|
+
export function List(value) {
|
|
5485
|
+
return transform(Array$(value), ListFromSelf(typeSchema(asSchema(value))), {
|
|
5449
5486
|
strict: true,
|
|
5450
|
-
decode:
|
|
5451
|
-
encode:
|
|
5487
|
+
decode: i => list_.fromIterable(i),
|
|
5488
|
+
encode: a => Array.from(a)
|
|
5452
5489
|
});
|
|
5453
|
-
}
|
|
5490
|
+
}
|
|
5454
5491
|
const sortedSetArbitrary = (item, ord, ctx) => fc => {
|
|
5455
5492
|
const items = fc.array(item(fc));
|
|
5456
5493
|
return (ctx.depthIdentifier !== undefined ? fc.oneof(ctx, fc.constant([]), items) : items).map(as => sortedSet_.fromIterable(as, ord));
|
|
@@ -5476,15 +5513,14 @@ export const SortedSetFromSelf = (value, ordA, ordI) => {
|
|
|
5476
5513
|
* @category SortedSet transformations
|
|
5477
5514
|
* @since 3.10.0
|
|
5478
5515
|
*/
|
|
5479
|
-
export
|
|
5480
|
-
const
|
|
5481
|
-
|
|
5482
|
-
return transform(Array$(value_), SortedSetFromSelf(to, ordA, ordA), {
|
|
5516
|
+
export function SortedSet(value, ordA) {
|
|
5517
|
+
const to = typeSchema(asSchema(value));
|
|
5518
|
+
return transform(Array$(value), SortedSetFromSelf(to, ordA, ordA), {
|
|
5483
5519
|
strict: true,
|
|
5484
|
-
decode:
|
|
5485
|
-
encode:
|
|
5520
|
+
decode: i => sortedSet_.fromIterable(i, ordA),
|
|
5521
|
+
encode: a => Array.from(sortedSet_.values(a))
|
|
5486
5522
|
});
|
|
5487
|
-
}
|
|
5523
|
+
}
|
|
5488
5524
|
/**
|
|
5489
5525
|
* Converts an arbitrary value to a `boolean` by testing whether it is truthy.
|
|
5490
5526
|
* Uses `!!val` to coerce the value to a `boolean`.
|
|
@@ -5495,7 +5531,7 @@ export const SortedSet = (value, ordA) => {
|
|
|
5495
5531
|
*/
|
|
5496
5532
|
export class BooleanFromUnknown extends /*#__PURE__*/transform(Unknown, Boolean$, {
|
|
5497
5533
|
strict: true,
|
|
5498
|
-
decode: Predicate.isTruthy,
|
|
5534
|
+
decode: i => Predicate.isTruthy(i),
|
|
5499
5535
|
encode: identity
|
|
5500
5536
|
}).annotations({
|
|
5501
5537
|
identifier: "BooleanFromUnknown"
|
|
@@ -5511,8 +5547,8 @@ export class BooleanFromString extends /*#__PURE__*/transform(Literal("true", "f
|
|
|
5511
5547
|
description: "a string to be decoded into a boolean"
|
|
5512
5548
|
}), Boolean$, {
|
|
5513
5549
|
strict: true,
|
|
5514
|
-
decode:
|
|
5515
|
-
encode:
|
|
5550
|
+
decode: i => i === "true",
|
|
5551
|
+
encode: a => a ? "true" : "false"
|
|
5516
5552
|
}).annotations({
|
|
5517
5553
|
identifier: "BooleanFromString"
|
|
5518
5554
|
}) {}
|
|
@@ -5858,6 +5894,18 @@ const go = (ast, path) => {
|
|
|
5858
5894
|
}
|
|
5859
5895
|
}
|
|
5860
5896
|
};
|
|
5897
|
+
const SymbolStruct = /*#__PURE__*/TaggedStruct("symbol", {
|
|
5898
|
+
key: String$
|
|
5899
|
+
}).annotations({
|
|
5900
|
+
description: "an object to be decoded into a globally shared symbol"
|
|
5901
|
+
});
|
|
5902
|
+
const SymbolFromStruct = /*#__PURE__*/transformOrFail(SymbolStruct, SymbolFromSelf, {
|
|
5903
|
+
strict: true,
|
|
5904
|
+
decode: i => decodeSymbol(i.key),
|
|
5905
|
+
encode: (a, _, ast) => ParseResult.map(encodeSymbol(a, ast), key => SymbolStruct.make({
|
|
5906
|
+
key
|
|
5907
|
+
}))
|
|
5908
|
+
});
|
|
5861
5909
|
/** @ignore */
|
|
5862
5910
|
class PropertyKey$ extends /*#__PURE__*/Union(String$, Number$, SymbolFromStruct).annotations({
|
|
5863
5911
|
identifier: "PropertyKey"
|