Skip to content
On this page

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
idStringKebab-cased plug-in ID. Required.
meta[Function][]import.meta. Required.
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()async functionCreate a file on the content store.
readFile()async functionRead a file from the content store.
updateFile()async functionUpdate a file on the content store.
deleteFile()async functionDelete a file on the content store.

createFile()

ParametersTypeDescription
pathStringPath to file. Required.
contentStringFile content. Required.
messageStringCommit message. Optional.

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

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

readFile()

ParametersTypeDescription
pathStringPath to file. Required.

Returns content as a String if successful, else returns IndiekitError. For example:

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

updateFile()

ParametersTypeDescription
pathStringPath to file. Required.
contentStringFile content. Required.
messageStringCommit message. Optional.

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

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

deleteFile()

ParametersTypeDescription
pathStringPath to file. Required.
messageStringCommit message. Optional.

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

js
async deleteFile(path, message) {
  try {
    await exampleClient.delete(path, content, 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.meta = import.meta;
    this.name = "Example store";
  }

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

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

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

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

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

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

Example content store plug-ins: