{"version":3,"file":"main.cjs","sources":["../src/schema.mts","../src/number.mts","../src/string.mts","../src/regexp.mts","../src/array.mts","../src/object.mts","../src/union.mts"],"sourcesContent":["import type { FastBrand } from '@coderspirit/nominal'\nimport type {\n\tHint,\n\tKind,\n\tOptionalKind,\n\tReadonlyKind,\n\tTSchema,\n} from '@sinclair/typebox'\n\nexport type BrandedSchema<B extends string, T extends TSchema> = Pick<\n\tT,\n\t| typeof Kind\n\t| typeof ReadonlyKind\n\t| typeof OptionalKind\n\t| typeof Hint\n\t| '$schema'\n\t| '$id'\n\t| 'title'\n\t| 'description'\n\t| 'default'\n\t| 'examples'\n\t| 'readOnly'\n\t| 'writeOnly'\n\t| 'params'\n\t// We leave out `static` on purpose, but we also loose some other properties\n\t// that might exist in TSchema subtypes, we can't do anything about it without\n\t// overcomplicating the code.\n> & {\n\tstatic: FastBrand<T['static'], B>\n}\n\nexport const brandedSchema = <const B extends string, S extends TSchema>(\n\t_b: B,\n\tschema: S,\n): BrandedSchema<B, S> => {\n\treturn schema as BrandedSchema<B, S>\n}\n","import type { FastBrand, FastBrandAndProperties } from '@coderspirit/nominal'\nimport type { IntegerOptions, NumberOptions, TSchema } from '@sinclair/typebox'\nimport { Kind } from '@sinclair/typebox'\nimport { Integer as TBInteger, Number as TBNumber } from '@sinclair/typebox'\n\nexport interface BrandedIntegerSchema<B extends string>\n\textends TSchema,\n\t\tIntegerOptions {\n\t// Copied from TInteger\n\t[Kind]: 'Integer'\n\ttype: 'integer'\n\n\t// Our sauce\n\tstatic: FastBrandAndProperties<number, B, { Fractional: false }>\n}\n\nexport interface BrandedNumberSchema<B extends string>\n\textends TSchema,\n\t\tNumberOptions {\n\t// Copied from TNumber\n\t[Kind]: 'Number'\n\ttype: 'number'\n\n\t// Our sauce\n\tstatic: FastBrand<number, B>\n}\n\nexport const brandedInteger = <const B extends string>(\n\toptions?: IntegerOptions,\n): BrandedIntegerSchema<B> => {\n\treturn TBInteger(options) as BrandedIntegerSchema<B>\n}\n\nexport const brandedNumber = <const B extends string>(\n\toptions?: NumberOptions,\n): BrandedNumberSchema<B> => {\n\treturn TBNumber(options) as BrandedNumberSchema<B>\n}\n","import type { FastBrand } from '@coderspirit/nominal'\nimport type { Kind, StringOptions, TSchema } from '@sinclair/typebox'\nimport { String as TBString } from '@sinclair/typebox'\n\nexport interface BrandedStringSchema<B extends string>\n\textends TSchema,\n\t\tStringOptions {\n\t// Copied from TString\n\t[Kind]: 'String'\n\ttype: 'string'\n\n\t// Our sauce\n\tstatic: FastBrand<string, B>\n}\n\nexport const brandedString = <const B extends string>(\n\toptions?: StringOptions,\n): BrandedStringSchema<B> => {\n\treturn TBString(options) as BrandedStringSchema<B>\n}\n","import type { FastBrand } from '@coderspirit/nominal'\nimport type { Kind, RegExpOptions, TSchema } from '@sinclair/typebox'\nimport { RegExp as TBRegExp } from '@sinclair/typebox'\n\nexport interface BrandedRegExpSchema<B extends string> extends TSchema {\n\t// Copied from TRegExp\n\t[Kind]: 'RegExp'\n\ttype: 'RegExp'\n\tsource: string\n\tflags: string\n\n\t// Our sauce\n\tstatic: FastBrand<string, B>\n}\n\nfunction brandedRegExp<const B extends string>(\n\tregex: RegExp,\n\toptions?: RegExpOptions,\n): BrandedRegExpSchema<B>\nfunction brandedRegExp<const B extends string>(\n\tregex: string,\n\toptions?: RegExpOptions,\n): BrandedRegExpSchema<B>\nfunction brandedRegExp<const B extends string>(\n\tpattern: string | RegExp,\n\toptions?: RegExpOptions,\n): BrandedRegExpSchema<B> {\n\treturn TBRegExp(pattern as string, options) as BrandedRegExpSchema<B>\n}\n\nexport { brandedRegExp }\n","import type { FastBrand } from '@coderspirit/nominal'\nimport type { ArrayOptions, Kind, TArray, TSchema } from '@sinclair/typebox'\nimport { Array as TBArray } from '@sinclair/typebox'\n\nexport interface BrandedArraySchema<\n\tB extends string,\n\tS extends TSchema,\n\tA extends TArray<S>,\n> extends TSchema,\n\t\tArrayOptions {\n\t// We cannot rely on `&`, `extends` or generics here, because that would\n\t// impose too much work on the type inference engine.\n\n\t// Copied from TArray\n\t[Kind]: 'Array'\n\ttype: 'array'\n\titems: S\n\n\t// Our special sauce\n\tstatic: FastBrand<A['static'], B>\n}\n\nexport const brandedArray = <const B extends string, const S extends TSchema>(\n\t_b: B,\n\tschema: S,\n\toptions?: ArrayOptions,\n): BrandedArraySchema<B, S, TArray<S>> => {\n\t// We have to separate declaration and return statement because otherwise\n\t// TS goes crazy, thinking that there is some kind of type circularity.\n\treturn TBArray(schema, options) as BrandedArraySchema<B, S, TArray<S>>\n}\n","import type { FastBrand } from '@coderspirit/nominal'\nimport type {\n\tKind,\n\tObjectOptions,\n\tTObject,\n\tTProperties,\n\tTSchema,\n} from '@sinclair/typebox'\nimport { Object as TBObject } from '@sinclair/typebox'\n\nexport interface BrandedObjectSchema<\n\tB extends string,\n\tT extends TProperties,\n\tO extends TObject<T>,\n> extends TSchema,\n\t\tObjectOptions {\n\t// We cannot rely on `&`, `extends` or generics here, because that would\n\t// impose too much work on the type inference engine.\n\n\t// Copied from TObject\n\t[Kind]: 'Object'\n\ttype: 'object'\n\tproperties: T\n\trequired?: string[]\n\n\t// Our special sauce\n\tstatic: FastBrand<O['static'], B>\n}\n\nexport const brandedObject = <\n\tconst B extends string,\n\tconst T extends TProperties,\n>(\n\t_b: B,\n\tproperties: T,\n\toptions?: ObjectOptions,\n): BrandedObjectSchema<B, T, TObject<T>> => {\n\treturn TBObject(properties, options) as BrandedObjectSchema<B, T, TObject<T>>\n}\n","import type { FastBrand } from '@coderspirit/nominal'\nimport type {\n\tKind,\n\tSchemaOptions,\n\tStatic,\n\tTNever,\n\tTSchema,\n} from '@sinclair/typebox'\nimport { Union as TBUnion } from '@sinclair/typebox'\n\nimport type { BrandedSchema } from './schema.mts'\n\n// Private types\n// -----------------------------------------------------------------------------\ntype _UnionStatic<T extends TSchema[], P extends unknown[]> = {\n\t[K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never\n}[number]\n\ninterface _BrandedUnionSchema<B extends string, T extends TSchema[] = TSchema[]>\n\textends TSchema {\n\t// Copied from TUnion\n\t[Kind]: 'Union'\n\tanyOf: T\n\n\t// Our special sauce\n\tstatic: FastBrand<_UnionStatic<T, this['params']>, B>\n}\n\n// Stuff to be exported\n// -----------------------------------------------------------------------------\nexport type BrandedUnionSchema<\n\tB extends string,\n\tT extends TSchema[],\n> = T extends []\n\t? TNever\n\t: T extends [TSchema]\n\t\t? BrandedSchema<B, T[0]>\n\t\t: _BrandedUnionSchema<B, T>\n\nexport const brandedUnion = <B extends string, T extends TSchema[]>(\n\t_b: B,\n\tt: [...T],\n\toptions?: SchemaOptions,\n): BrandedUnionSchema<B, T> => {\n\treturn TBUnion(t, options) as BrandedUnionSchema<B, T>\n}\n"],"names":["brandedSchema","_b","schema","brandedInteger","options","TBInteger","brandedNumber","TBNumber","brandedString","TBString","brandedRegExp","pattern","TBRegExp","brandedArray","TBArray","brandedObject","properties","TBObject","brandedUnion","t","TBUnion"],"mappings":"gDA+Ba,MAAAA,EAAgB,CAC5BC,EACAC,IAEOA,ECRKC,EACZC,GAEOC,UAAUD,CAAO,EAGZE,EACZF,GAEOG,EAAAA,OAASH,CAAO,ECrBXI,EACZJ,GAEOK,EAAAA,OAASL,CAAO,ECKxB,SAASM,EACRC,EACAP,EACyB,CACzB,OAAOQ,SAASD,EAAmBP,CAAO,CAC3C,CCNa,MAAAS,EAAe,CAC3BZ,EACAC,EACAE,IAIOU,EAAAA,MAAQZ,EAAQE,CAAO,ECAlBW,EAAgB,CAI5Bd,EACAe,EACAZ,IAEOa,EAAAA,OAASD,EAAYZ,CAAO,ECEvBc,EAAe,CAC3BjB,EACAkB,EACAf,IAEOgB,EAAAA,MAAQD,EAAGf,CAAO"}