UNPKG

convex

Version:

Client for the Convex Cloud

126 lines 5.89 kB
import { ProjectConfig } from "../config.js"; import { RequestInitRetryParams } from "fetch-retry"; import { Context } from "../../../bundler/context.js"; export declare const productionProvisionHost = "https://provision.convex.dev"; export declare const provisionHost: string; export declare const CONVEX_DEPLOY_KEY_ENV_VAR_NAME = "CONVEX_DEPLOY_KEY"; export declare function parsePositiveInteger(value: string): number; export declare function parseInteger(value: string): number; export type ErrorData = { code: string; message: string; }; /** * Error thrown on non-2XX reponse codes to make most `fetch()` error handling * follow a single code path. */ export declare class ThrowingFetchError extends Error { response: Response; serverErrorData?: ErrorData; constructor(msg: string, { code, message, response, }: { cause?: Error; code?: string; message?: string; response: Response; }); static fromResponse(response: Response, msg?: string): Promise<ThrowingFetchError>; handle(ctx: Context): Promise<never>; } /** * Thin wrapper around `fetch()` which throws a FetchDataError on non-2XX * responses which includes error code and message from the response JSON. * (Axios-style) * * It also accepts retry options from fetch-retry. */ export declare function throwingFetch(resource: RequestInfo | URL, options: (RequestInit & RequestInitRetryParams) | undefined): Promise<Response>; /** * Handle an error a fetch error or non-2xx response. */ export declare function logAndHandleFetchError(ctx: Context, err: unknown): Promise<never>; export declare function deprecationCheckWarning(ctx: Context, resp: Response): void; export declare function hasTeam(ctx: Context, teamSlug: string): Promise<boolean>; export declare function validateOrSelectTeam(ctx: Context, teamSlug: string | undefined, promptMessage: string): Promise<{ teamSlug: string; chosen: boolean; }>; export declare function hasProject(ctx: Context, teamSlug: string, projectSlug: string): Promise<boolean>; export declare function hasProjects(ctx: Context): Promise<boolean>; export declare function validateOrSelectProject(ctx: Context, projectSlug: string | undefined, teamSlug: string, singleProjectPrompt: string, multiProjectPrompt: string): Promise<string | null>; /** * @param ctx * @returns a Record of dependency name to dependency version for dependencies * and devDependencies */ export declare function loadPackageJson(ctx: Context, includePeerDeps?: boolean): Promise<Record<string, string>>; export declare function ensureHasConvexDependency(ctx: Context, cmd: string): Promise<undefined>; /** Return a new array with elements of the passed in array sorted by a key lambda */ export declare const sorted: <T>(arr: T[], key: (el: T) => any) => T[]; export declare function functionsDir(configPath: string, projectConfig: ProjectConfig): string; export declare function rootDirectory(): string; export declare function globalConfigPath(): string; export declare function readAdminKeyFromEnvVar(): string | undefined; export declare function getAuthHeaderForBigBrain(ctx: Context): Promise<string | null>; export declare function bigBrainFetch(ctx: Context): Promise<typeof fetch>; export declare function bigBrainAPI({ ctx, method, url, data, }: { ctx: Context; method: string; url: string; data?: any; }): Promise<any>; export declare function bigBrainAPIMaybeThrows({ ctx, method, url, data, }: { ctx: Context; method: string; url: string; data?: any; }): Promise<any>; export type GlobalConfig = { accessToken: string; }; /** * Polls an arbitrary function until a condition is met. * * @param fetch Function performing a fetch, returning resulting data. * @param condition This function will terminate polling when it returns `true`. * @param waitMs How long to wait in between fetches. * @returns The resulting data from `fetch`. */ export declare const poll: <Result>(fetch: () => Promise<Result>, condition: (data: Result) => boolean, waitMs?: number) => Promise<Result>; export declare function waitForever(): Promise<unknown>; export declare function waitUntilCalled(): [Promise<unknown>, () => void]; export declare function formatSize(n: number): string; export declare function formatDuration(ms: number): string; export declare function getCurrentTimeString(): string; export declare function findParentConfigs(ctx: Context): Promise<{ parentPackageJson: string; parentConvexJson?: string; }>; /** * Returns whether there's an existing project config. Throws * if this is not a valid directory for a project config. */ export declare function isInExistingProject(ctx: Context): Promise<boolean>; export declare function getConfiguredDeploymentOrCrash(ctx: Context): Promise<string>; export declare function getConfiguredDeploymentName(ctx: Context): Promise<string | null>; export declare function spawnAsync(ctx: Context, command: string, args: ReadonlyArray<string>): Promise<{ stdout: string; stderr: string; status: null | number; error?: Error | undefined; }>; export declare function spawnAsync(ctx: Context, command: string, args: ReadonlyArray<string>, options: { stdio: "inherit"; }): Promise<void>; /** * Unlike `deploymentFetch`, this does not add on any headers, so the caller * must supply any headers. */ export declare function bareDeploymentFetch(deploymentUrl: string, onError?: (err: any) => void): typeof throwingFetch; /** * This returns a `fetch` function that will fetch against `deploymentUrl`. * * It will also set the `Authorization` header, `Content-Type` header, and * the `Convex-Client` header if they are not set in the `fetch`. */ export declare function deploymentFetch(deploymentUrl: string, adminKey: string, onError?: (err: any) => void): typeof throwingFetch; //# sourceMappingURL=utils.d.ts.map