Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript types #30

Open
SferaDev opened this issue Oct 11, 2023 · 2 comments
Open

Add TypeScript types #30

SferaDev opened this issue Oct 11, 2023 · 2 comments

Comments

@SferaDev
Copy link

SferaDev commented Oct 11, 2023

Something similar to:

declare module "@astrajs/rest" {
  import { AxiosRequestConfig } from "axios";

  interface AstraClientOptions {
    configFile?: string;
    configSection?: string;
    baseApiPath?: string;
    baseUrl?: string;
    authUrl?: string;
    authToken?: string;
    applicationToken?: string;
    autoReconnect?: boolean;
    getAuthToken?: () => Promise<string>;
    setAuthToken?: (authToken: string) => Promise<void>;
    username?: string;
    password?: string;
    debug?: boolean;
    authHeaderName?: string;
    astraDatabaseId?: string;
    astraDatabaseRegion?: string;
  }

  interface AstraClient extends AstraClientOptions {
    get: (
      path: string,
      options?: AxiosRequestConfig
    ) => Promise<{ status: number; data: any }>;
    post: (
      path: string,
      data: any,
      options?: AxiosRequestConfig
    ) => Promise<{ status: number; data: any }>;
    put: (
      path: string,
      data: any,
      options?: AxiosRequestConfig
    ) => Promise<{ status: number; data: any }>;
    patch: (
      path: string,
      data: any,
      options?: AxiosRequestConfig
    ) => Promise<{ status: number; data: any }>;
    delete: (
      path: string,
      options?: AxiosRequestConfig
    ) => Promise<{ status: number; data: any }>;
  }

  export function createClient(
    options: AstraClientOptions
  ): Promise<AstraClient>;

  export function axiosRequest(
    options: AxiosRequestConfig & {
      authToken?: string;
      applicationToken?: string;
      authHeaderName?: string;
    }
  ): Promise<{ status: number; data: any }>;
}

Of course types could be improved further, but this at least offers a first step.

Disclaimer: Copilot chat might have or might have not generated this dts file.

@PanditSiddharth
Copy link

PanditSiddharth commented Jan 27, 2024

Yes right and also options field with available astra options like
where {
$eq: "..."
}

Btw instead of issue pull request will be better

@SferaDev
Copy link
Author

I only used Astra db for a workshop and wasn't planning on maintaining anything so decided to open an issue instead with what helped me work for ~2 hours 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants