import { RawCoID } from "./ids.js"; export type JsonAtom = string | number | boolean | null; export type JsonValue = JsonAtom | JsonArray | JsonObject | RawCoID; export type JsonArray = JsonValue[] | readonly JsonValue[]; export type JsonObject = { [key: string]: JsonValue | undefined; }; type AtLeastOne; }> = Partial & U[keyof U]; type ExcludeEmpty = T extends AtLeastOne ? T : never; type ExcludeNull = T extends null ? never : T; type IsFunction = T extends (...args: any[]) => any ? true : false; type ContainsSymbolKeys = keyof ExcludeNull extends symbol ? true : false; export type CoJsonValue = IsFunction extends true ? "Functions are not allowed" : ContainsSymbolKeys extends true ? "Only string or number keys are allowed" : JsonValue | CoJsonObjectWithIndex | CoJsonArray; export type CoJsonArray = CoJsonValue[] | readonly CoJsonValue[]; /** * Since we are forcing Typescript to elaborate the indexes from the given type passing * non-object values to CoJsonObjectWithIndex will return an empty object * E.g. * CoJsonObjectWithIndex<() => void> --> {} * CoJsonObjectWithIndex --> {} * * Applying the ExcludeEmpty type here to make sure we don't accept functions or non-serializable values */ export type CoJsonObjectWithIndex = ExcludeEmpty<{ [K in keyof T]: CoJsonValue1L | undefined; }>; /** * Manually handling the nested interface types to not get into infinite recursion issues. */ export type CoJsonValue1L = ExcludeEmpty<{ [K in keyof T & string]: CoJsonValue2L | undefined; }> | JsonValue; export type CoJsonValue2L = ExcludeEmpty<{ [K in keyof T & string]: CoJsonValue3L | undefined; }> | JsonValue; export type CoJsonValue3L = ExcludeEmpty<{ [K in keyof T & string]: CoJsonValue4L | undefined; }> | JsonValue; export type CoJsonValue4L = ExcludeEmpty<{ [K in keyof T & string]: JsonValue | undefined; }> | JsonValue; export {}; //# sourceMappingURL=jsonValue.d.ts.map