UNPKG

@graphql-hive/cli

Version:

A CLI util to manage and control your GraphQL Hive

87 lines 3.51 kB
import type { TypedDocumentNode } from '@graphql-typed-document-node/core'; import { Command, Interfaces } from '@oclif/core'; import { Config, GetConfigurationValueType, ValidConfigurationKeys } from './helpers/config'; export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof BaseCommand)['baseFlags'] & T['flags']>; export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>; type OmitNever<T> = { [K in keyof T as T[K] extends never ? never : K]: T[K]; }; export default abstract class BaseCommand<T extends typeof Command> extends Command { protected _userConfig: Config | undefined; static baseFlags: { debug: Interfaces.BooleanFlag<boolean>; }; protected flags: Flags<T>; protected args: Args<T>; protected get userConfig(): Config; init(): Promise<void>; success(...args: any[]): void; fail(...args: any[]): void; info(...args: any[]): void; infoWarning(...args: any[]): void; bolderize(msg: string): string; maybe<TArgs extends Record<string, any>, TKey extends keyof TArgs>({ key, env, args, }: { key: TKey; env: string; args: TArgs; }): string | NonNullable<TArgs[TKey]> | undefined; /** * Get a value from arguments or flags first, then from env variables, * then fallback to config. * Throw when there's no value. * * @param key * @param args all arguments or flags * @param defaultValue default value * @param message custom error message in case of no value * @param env an env var name */ ensure<TKey extends ValidConfigurationKeys, TArgs extends { [key in TKey]: GetConfigurationValueType<TKey>; }>({ key, args, legacyFlagName, defaultValue, message, env, }: { args: TArgs; key: TKey; /** By default we try to match config names with flag names, but for legacy compatibility we need to provide the old flag name. */ legacyFlagName?: keyof OmitNever<{ [TArgKey in keyof TArgs]: typeof Symbol.asyncIterator extends TArgs[TArgKey] ? never : string extends TArgs[TArgKey] ? TArgKey : never; }>; defaultValue?: TArgs[keyof TArgs] | null; message?: string; env?: string; }): NonNullable<GetConfigurationValueType<TKey>> | never; cleanRequestId(requestId?: string | null): string | undefined; registryApi(registry: string, token: string): { request<TResult, TVariables>(args: { operation: TypedDocumentNode<TResult, TVariables>; /** timeout in milliseconds */ timeout?: number; } & (TVariables extends Record<string, never> ? { variables?: never; } : { variables: TVariables; })): Promise<TResult>; }; handleFetchError(error: unknown): never; require<TFlags extends { require: string[]; [key: string]: any; }>(flags: TFlags): Promise<void>; } export declare function graphqlRequest(config: { endpoint: string; additionalHeaders?: Record<string, string>; version?: string; debug?: boolean; }): { request<TResult, TVariables>(args: { operation: TypedDocumentNode<TResult, TVariables>; /** timeout in milliseconds */ timeout?: number; } & (TVariables extends Record<string, never> ? { variables?: never; } : { variables: TVariables; })): Promise<TResult>; }; export {}; //# sourceMappingURL=base-command.d.ts.map