Skip to content

Indiekit.addStore

A content store plug-in interfaces with CRUD (create, read, update, delete) methods provided by a file system, server, database or API.

Constructor

PropertyTypeDescription
nameStringHuman readable plug-in name. Required.
optionsObjectPlug-in options. Optional.

Properties

PropertyTypeDescription
infoObjectInformation about the content store. Required.

info

Indiekit’s web interface expects a content store plugin to provide some information about the content store it supports. This is provided by the info property:

js
get info() {
  return {
    name: "Example content store",
    uid: "https://store.example"
  };
}

The info property returns the following values:

PropertyTypeDescription
nameStringThe name of the content store the preset supports. Required.
uidStringURL or path to content store. Required.

Methods

MethodTypeDescription
createFile()AsyncFunctionCreate a file on the content store.
readFile()AsyncFunctionRead a file from the content store.
updateFile()AsyncFunctionUpdate a file on the content store.
deleteFile()AsyncFunctionDelete a file on the content store.

createFile()

ParametersTypeDescription
filePathStringPath to file. Required.
contentStringFile content. Required.
options.messageStringCommit message. Optional.

Returns a String containing the file’s URL if successful, else returns IndiekitError. For example:

js
async createFile(filePath, content, { message }) {
  try {
    await exampleClient.create(filePath, content, message);
    return true;
  } catch (error) {
    throw new IndiekitError(error.message);
  }
}

readFile()

ParametersTypeDescription
filePathStringPath to file. Required.

Returns content as a String containing the file’s content if successful, else returns IndiekitError. For example:

js
async readFile(filePath) {
  try {
    await exampleClient.read(filePath);
    return true;
  } catch (error) {
    throw new IndiekitError(error.message);
  }
}

updateFile()

ParametersTypeDescription
filePathStringPath to file. Required.
contentStringFile content. Required.
options.messageStringCommit message. Optional.
options.newPathStringNew path to file. Optional.

Returns a String containing the file’s updated URL if successful, else returns IndiekitError. For example:

js
async updateFile(filePath, content, { message, newPath }) {
  try {
    await exampleClient.update(filePath, content, message, newPath);
    return true;
  } catch (error) {
    throw new IndiekitError(error.message);
  }
}

deleteFile()

ParametersTypeDescription
filePathStringPath to file. Required.
options.messageStringCommit message. Optional.

Returns a Boolean true if successful, else returns IndiekitError. For example:

js
async deleteFile(filePath, { message }) {
  try {
    await exampleClient.delete(filePath, message);
    return true;
  } catch (error) {
    throw new IndiekitError(error.message);
  }
}

Example

js
import { IndiekitError } from "@indiekit/error";
import exampleClient from 'example-client';

export default class ExampleStore {
  constructor() {
    this.id = "example-store";
    this.name = "Example store";
  }

  get info() {
    return {
      name: "Example application",
      uid: "https://store.example"
    };
  }

  async createFile(filePath, content, message) {
    try {
      await exampleClient.create(filePath, content, message);
      return true;
    } catch (error) {
      throw new IndiekitError(error.message);
    }
  }

  async readFile(filePath) {
    try {
      await exampleClient.read(filePath);
      return true;
    } catch (error) {
      throw new IndiekitError(error.message);
    }
  }

  async updateFile(filePath, content, message) {
    try {
      await exampleClient.update(filePath, content, message);
      return true;
    } catch (error) {
      throw new IndiekitError(error.message);
    }
  }

  async deleteFile(filePath, message) {
    try {
      await exampleClient.delete(filePath, content, message);
      return true;
    } catch (error) {
      throw new IndiekitError(error.message);
    }
  }

  init(Indiekit) {
    Indiekit.addStore(this);
  }
}

Example content store plug-ins: