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
idStringKebab-cased plug-in ID. Required.
metaimport.metaRequired.
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"
  };
}
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
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);
  }
}
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);
  }
}
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);
  }
}
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);
  }
}
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.meta = import.meta;
    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);
  }
}
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(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: