{"size": 4764, "ext": "js", "max_stars_repo_path": "packages/client/src/schemas.js", "max_stars_repo_name": "alexleventer/astrajs", "max_stars_repo_stars_event_min_datetime": "2020-12-10T22:22:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T12:59:24.000Z", "max_issues_repo_path": "packages/client/src/schemas.js", "max_issues_repo_name": "alexleventer/astrajs", "max_issues_repo_issues_event_min_datetime": "2021-03-26T01:21:39.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-18T18:06:21.000Z", "max_forks_repo_path": "packages/client/src/schemas.js", "max_forks_repo_name": "alexleventer/astrajs", "max_forks_repo_forks_event_min_datetime": "2021-01-13T10:25:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-28T22:25:11.000Z"}
{"max_stars_count": 13, "max_issues_count": 11, "max_forks_count": 10, "avg_line_length": 26.0327868852, "max_line_length": 81, "alphanum_fraction": 0.6469353484}
// Copyright DataStax, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

"use strict";

class AstraSchemas {
  constructor(client) {
    this.basePath = client.baseApiPath
      ? client.baseApiPath
      : "/api/rest/v2/schemas";
    this.client = client;
  }

  async getKeyspaces() {
    const res = await this.client.get(`${this.basePath}/keyspaces`);
    return res.data;
  }

  async getKeyspace(keyspace) {
    const res = await this.client.get(`${this.basePath}/keyspaces/${keyspace}`);
    return res.data;
  }

  async createKeyspace(keyspace) {
    const res = await this.client.post(`${this.basePath}/keyspaces`, keyspace);
    return res.data;
  }

  async deleteKeyspace(keyspace) {
    const res = await this.client.delete(
      `${this.basePath}/keyspaces/${keyspace}`
    );
    return res.data;
  }

  async createTable(keyspace, table) {
    const res = await this.client.post(
      `${this.basePath}/keyspaces/${keyspace}/tables`,
      table
    );

    return res.data;
  }

  async getTables(keyspace) {
    const res = await this.client.get(
      `${this.basePath}/keyspaces/${keyspace}/tables`
    );
    return res.data;
  }

  async getTable(keyspace, table) {
    const res = await this.client.get(
      `${this.basePath}/keyspaces/${keyspace}/tables/${table}`
    );
    return res.data;
  }

  async updateTable(keyspace, table, tableDefinition) {
    const res = await this.client.put(
      `${this.basePath}/keyspaces/${keyspace}/tables/${table}`,
      tableDefinition
    );
    return res.data;
  }

  async deleteTable(keyspace, table) {
    const res = await this.client.delete(
      `${this.basePath}/keyspaces/${keyspace}/tables/${table}`
    );
    return res.data;
  }

  async createColumn(keyspace, table, columnDefinition) {
    const res = await this.client.post(
      `${this.basePath}/keyspaces/${keyspace}/tables/${table}/columns`,
      columnDefinition
    );
    return res.data;
  }

  async getColumns(keyspace, table) {
    const res = await this.client.get(
      `${this.basePath}/keyspaces/${keyspace}/tables/${table}/columns`
    );
    return res.data;
  }

  async getColumn(keyspace, table, column) {
    const res = await this.client.get(
      `${this.basePath}/keyspaces/${keyspace}/tables/${table}/columns/${column}`
    );
    return res.data;
  }

  async updateColumn(keyspace, table, column, columnDefinition) {
    const res = await this.client.put(
      `${this.basePath}/keyspaces/${keyspace}/tables/${table}/columns/${column}`,
      columnDefinition
    );
    return res.data;
  }

  async deleteColumn(keyspace, table, column) {
    const res = await this.client.delete(
      `${this.basePath}/keyspaces/${keyspace}/tables/${table}/columns/${column}`
    );
    return res.data;
  }

  async getIndexes(keyspace, table) {
    const res = await this.client.get(
      `${this.basePath}/keyspaces/${keyspace}/tables/${table}/indexes`
    );
    return res.data;
  }

  async createIndex(keyspace, table, indexDefinition) {
    const res = await this.client.post(
      `${this.basePath}/keyspaces/${keyspace}/tables/${table}/indexes`,
      indexDefinition
    );
    return res.data;
  }

  async deleteIndex(keyspace, table, index) {
    const res = await this.client.delete(
      `${this.basePath}/keyspaces/${keyspace}/tables/${table}/indexes/${index}`
    );
    return res.data;
  }

  async getTypes(keyspace) {
    const res = await this.client.get(
      `${this.basePath}/keyspaces/${keyspace}/types`
    );
    return res.data;
  }

  async getType(keyspace, type) {
    const res = await this.client.get(
      `${this.basePath}/keyspaces/${keyspace}/types/${type}`
    );
    return res.data;
  }

  async createType(keyspace, type) {
    const res = await this.client.post(
      `${this.basePath}/keyspaces/${keyspace}/types`,
      type
    );
    return res.data;
  }

  async updateType(keyspace, type) {
    const res = await this.client.put(
      `${this.basePath}/keyspaces/${keyspace}/types`,
      type
    );
    return res.data;
  }

  async deleteType(keyspace, type) {
    const res = await this.client.delete(
      `${this.basePath}/keyspaces/${keyspace}/types/${type}`
    );
    return res.data;
  }
}

module.exports = { AstraSchemas };
