( constructor: Brand.Constructor<C>, annotations?: Annotations.Filter<C, A> )
| 1111 | * @since 3.10.0 |
| 1112 | */ |
| 1113 | export const fromBrand = <C extends Brand<string | symbol>, A extends Brand.Unbranded<C>>( |
| 1114 | constructor: Brand.Constructor<C>, |
| 1115 | annotations?: Annotations.Filter<C, A> |
| 1116 | ) => |
| 1117 | <I, R>(self: Schema<A, I, R>): BrandSchema<A & C, I, R> => { |
| 1118 | const out = makeBrandClass( |
| 1119 | self, |
| 1120 | new AST.Refinement( |
| 1121 | self.ast, |
| 1122 | function predicate(a: A, _: ParseOptions, ast: AST.AST): option_.Option<ParseResult.ParseIssue> { |
| 1123 | const either = constructor.either(a) |
| 1124 | return either_.isLeft(either) ? |
| 1125 | option_.some(new ParseResult.Type(ast, a, either.left.map((v) => v.message).join(", "))) : |
| 1126 | option_.none() |
| 1127 | }, |
| 1128 | toASTAnnotations({ |
| 1129 | schemaId: BrandSchemaId, |
| 1130 | [BrandSchemaId]: { constructor }, |
| 1131 | ...annotations |
| 1132 | }) |
| 1133 | ) |
| 1134 | ) |
| 1135 | return out as any |
| 1136 | } |
| 1137 | |
| 1138 | /** |
| 1139 | * @category schema id |
nothing calls this directly
no test coverage detected
searching dependent graphs…