import type { GenericId } from "convex/values"; import type { Brand } from "effect"; export type IsOptional = {} extends Pick ? true : false; export type IsAny = 0 extends 1 & T ? true : false; export type IsUnion = T extends unknown ? [U] extends [T] ? false : true : never; // https://stackoverflow.com/a/52806744 export type IsValueLiteral = [Vl] extends [never] ? never : [Vl] extends [string | number | bigint | boolean] ? [string] extends [Vl] ? false : [number] extends [Vl] ? false : [boolean] extends [Vl] ? false : [bigint] extends [Vl] ? false : true : false; export type DeepMutable = IsAny extends true ? any : T extends Brand.Brand | GenericId ? T : T extends ReadonlyMap ? Map, DeepMutable> : T extends ReadonlySet ? Set> : [keyof T] extends [never] ? T : { -readonly [K in keyof T]: DeepMutable }; export type DeepReadonly = IsAny extends true ? any : T extends Map ? ReadonlyMap, DeepReadonly> : T extends Set ? ReadonlySet> : [keyof T] extends [never] ? T : { readonly [K in keyof T]: DeepReadonly }; export type TypeError = [Message, T]; export type IsRecursive = true extends DetectCycle ? true : false; type DetectCycle = IsAny extends true ? false : [T] extends [any] ? T extends Cache[number] ? true : T extends Array ? DetectCycle : T extends Map ? DetectCycle : T extends Set ? DetectCycle : T extends object ? true extends { [K in keyof T]: DetectCycle; }[keyof T] ? true : false : false : never; ////////////////////////////////// // START: Vendored from Arktype // ////////////////////////////////// // https://github.com/arktypeio/arktype/blob/2e911d01a741ccee7a17e31ee144049817fabbb8/ark/util/unionToTuple.ts#L9 export type UnionToTuple = _unionToTuple extends infer result ? conform : never; type _unionToTuple< t, result extends unknown[], > = getLastBranch extends infer current ? [t] extends [never] ? result : _unionToTuple, [current, ...result]> : never; type getLastBranch = intersectUnion void : never> extends ( x: infer branch, ) => void ? branch : never; type intersectUnion = (t extends unknown ? (_: t) => void : never) extends ( _: infer intersection, ) => void ? intersection : never; type conform = t extends base ? t : base; //////////////////////////////// // END: Vendored from Arktype // ////////////////////////////////