Link Search Menu Expand Document (external link)

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

Property Type Description
id String Kebab-cased plug-in ID. Required.
meta [Function][] import.meta. Required.
name String Human readable plug-in name. Required.
options Object Plug-in options. Optional.

Properties

Property Type Description
info Object Information 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:

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

The info property returns the following values:

Property Type Description
name String The name of the content store the preset supports. Required.
uid String URL or path to content store. Required.

Methods

Method Type Description
createFile() async function Create a file on the content store.
readFile() async function Read a file from the content store.
updateFile() async function Update a file on the content store.
deleteFile() async function Delete a file on the content store.

createFile()

Parameters Type Description
path String Path to file. Required.
content String File content. Required.
message String Commit message. Optional.

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

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

readFile()

Parameters Type Description
path String Path to file. Required.

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

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

updateFile()

Parameters Type Description
path String Path to file. Required.
content String File content. Required.
message String Commit message. Optional.

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

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

deleteFile()

Parameters Type Description
path String Path to file. Required.
message String Commit message. Optional.

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

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

Example

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: