// tracing: off import { pipe } from "@effect-ts/core/Function" import * as S from "../_schema.js" import { brand } from "./brand.js" import { fromNumber, number, stringNumberFromString } from "./number.js" import { string } from "./string.js" import type { DefaultSchema } from "./withDefaults.js" export interface IntBrand { readonly Int: unique symbol } export type Int = number & IntBrand export const intFromNumberIdentifier = S.makeAnnotation<{}>() export const intFromNumber: DefaultSchema = pipe( fromNumber, S.arbitrary(_ => _.integer()), S.refine( (n): n is Int => Number.isInteger(n), n => S.leafE(S.invalidIntegerE(n)) ), S.encoder(_ => _ as number), S.mapConstructorError(_ => (((_ as any).errors) as Chunk).unsafeHead.error), S.mapParserError(_ => (((_ as any).errors) as Chunk).unsafeHead.error), S.mapApi(() => ({})), brand(), S.annotate(intFromNumberIdentifier, {}) ) export const stringIntFromStringIdentifier = S.makeAnnotation<{}>() export const stringIntFromString: DefaultSchema< string, Int, number, string, S.ApiSelfType > = pipe( stringNumberFromString[">>>"](intFromNumber), brand(), S.annotate(stringIntFromStringIdentifier, {}) ) export const stringIntIdentifier = S.makeAnnotation<{}>() export const stringInt: DefaultSchema< unknown, Int, number, string, S.ApiSelfType > = pipe( string[">>>"](stringIntFromString), brand(), S.annotate(stringIntIdentifier, {}) ) export const intIdentifier = S.makeAnnotation<{}>() export const int: DefaultSchema< unknown, Int, number, number, S.ApiSelfType > = pipe(number[">>>"](intFromNumber), brand(), S.annotate(intIdentifier, {}))