graphql-gene
Version:
Generates automatically an executable schema out of your ORM models
1 lines • 2.56 kB
Source Map (JSON)
{"version":3,"file":"typeUtils.cjs","sources":["../../src/types/typeUtils.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyFunction = (...args: any) => any\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyObject = Record<string, any>\n\nexport type NestedObject = { [k: string]: NestedObject }\n\n/** Transform immutable objects to mutable */\nexport type Mutable<Immutable> = {\n -readonly [K in keyof Immutable]: Immutable[K]\n}\n\nexport function getMutable<T extends string>(immutable: T[] | readonly T[]) {\n return immutable as Mutable<T[]>\n}\n\nexport type Prop<T, K> = K extends keyof T ? T[K] : never\n\nexport type ValueOf<T> = T[keyof T]\n\nexport type SomeRequired<T, K extends keyof T> = T & { [k in K]-?: T[k] }\n\ntype NotPossiblyUndefinedKeys<T> = Exclude<\n { [k in keyof T]: T[k] extends Exclude<T[k], undefined> ? k : never }[keyof T],\n undefined\n>\n\nexport type PossiblyUndefinedToPartial<T> =\n NotPossiblyUndefinedKeys<T> extends never\n ? Partial<T>\n : SomeRequired<Partial<T>, NotPossiblyUndefinedKeys<T>>\n\ntype Hyphenize<T extends string, A extends string = ''> = T extends `${infer F}${infer R}`\n ? Kebab<R, `${A}${F extends Lowercase<F> ? '' : '-'}${Lowercase<F>}`>\n : A\n\ntype TrimHyphen<T extends string> = T extends `-${infer R}` ? R : T\n\nexport type Kebab<T extends string, A extends string = ''> = TrimHyphen<Hyphenize<T, A>>\nexport type NeverToUnknown<T> = T extends never ? unknown : T\n\n/**\n * A type that represents either a value of type T or a function that returns T.\n * Useful for avoiding circular dependencies by allowing lazy evaluation.\n */\nexport type TypeOrFunction<T> = T | (() => T)\n\n/**\n * Allow you to infer the values of an object inside another object without using `as const`.\n *\n * @example\n * function doSomething<T>(obj: Narrow<T>) {\n * return obj\n * }\n * const something = doSomething({ args: { page: 'Int' } })\n *\n * // `something.args.page` will be of type `'Int'` instead of `string`\n *\n * @see https://stackoverflow.com/a/75881801/1895428\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Narrow<T, SpecificProps = any> =\n | (T extends infer U ? U : never)\n | Extract<T, number | string | boolean | bigint | symbol | null | undefined | []>\n | ([T] extends [[]] ? [] : { [K in keyof T]: K extends SpecificProps ? Narrow<T[K]> : never })\n"],"names":["getMutable","immutable"],"mappings":"gFAYO,SAASA,EAA6BC,EAA+B,CAC1E,OAAOA,CACT"}