( from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined )
| 14181 | } |
| 14182 | |
| 14183 | function getClassSchemaFactory<S extends Constraint>( |
| 14184 | from: S, |
| 14185 | identifier: string, |
| 14186 | annotations: Annotations.Declaration<any, readonly [S]> | undefined |
| 14187 | ) { |
| 14188 | let memo: decodeTo<declareConstructor<any, S["Encoded"], readonly [S]>, S> | undefined |
| 14189 | return <Self extends (new(...args: ReadonlyArray<any>) => any) & { readonly identifier: string }>( |
| 14190 | self: Self |
| 14191 | ): decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S> => { |
| 14192 | if (memo !== undefined) { |
| 14193 | return memo |
| 14194 | } |
| 14195 | const ClassTypeId = getClassTypeId(identifier) |
| 14196 | const isClassValue: Predicate.Predicate<unknown> = (input) => |
| 14197 | input instanceof self || Predicate.hasProperty(input, ClassTypeId) |
| 14198 | const transformation = getClassTransformation(self) |
| 14199 | const to = make<declareConstructor<Self, S["Encoded"], readonly [S]>>( |
| 14200 | new SchemaAST.Declaration( |
| 14201 | [from.ast], |
| 14202 | () => (input, ast, options) => { |
| 14203 | return isClassValue(input) ? |
| 14204 | Effect.succeed(input) : |
| 14205 | Effect.fail(new SchemaIssue.InvalidType(ast, input, options)) |
| 14206 | }, |
| 14207 | { |
| 14208 | identifier, |
| 14209 | [InternalAnnotations.CONSTRUCTOR_ANNOTATION_KEY]: ( |
| 14210 | [from]: readonly [SchemaAST.AST] |
| 14211 | ): SchemaAST.ConstructorDescriptor => ({ |
| 14212 | isConstructed: isClassValue, |
| 14213 | link: new SchemaAST.Link(from, transformation) |
| 14214 | }), |
| 14215 | toCodec: ([from]: readonly [ConstraintCodec<S["Encoded"], S["Encoded"]>]) => |
| 14216 | new SchemaAST.Link(from.ast, transformation), |
| 14217 | toArbitrary: ([from]: readonly [Annotations.ToArbitrary.TypeParameter<S["Type"]>]) => () => ({ |
| 14218 | arbitrary: from.arbitrary.map((args: S["Type"]) => new self(args)), |
| 14219 | terminal: from.terminal?.map((args: S["Type"]) => new self(args)) |
| 14220 | }), |
| 14221 | toFormatter: ([from]: readonly [Formatter<S["Type"]>]) => (t: Self) => `${self.identifier}(${from(t)})`, |
| 14222 | [InternalAnnotations.SENTINELS_ANNOTATION_KEY]: SchemaAST.collectSentinels(from.ast), |
| 14223 | ...annotations |
| 14224 | } |
| 14225 | ) |
| 14226 | ) |
| 14227 | return memo = decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>(to, transformation)(from) |
| 14228 | } |
| 14229 | } |
| 14230 | |
| 14231 | function isStruct(schema: Struct.Fields | Struct<Struct.Fields>): schema is Struct<Struct.Fields> { |
| 14232 | return isSchema(schema) |
no test coverage detected