outline |
---|
deep |
A content store interfaces with CRUD (create, read, update, delete) methods provided by a file system, version control system, server, database or API.
new Indiekit.addStore(options);
options
: An object used to customise the behaviour of the plug-in.
info
: An object representing information about the content store. Required.
The info
property should return the following values:
name
: The name of the content store the plug-in supports. Required.
uid
: URL or path to content store. Required.
An async function that creates a file on the content store.
filePath
: A string representing the path to a file. Required.
content
: A string representing the file content. Required.
options.message
: A string representing the commit message.
A string containing the file’s URL if successful, else IndiekitError
.
An async function that reads a file from the content store.
filePath
: A string representing the path to a file. Required.
A string containing the file’s content if successful, else IndiekitError
.
An async function that updates a file on the content store.
filePath
: A string representing the path to a file. Required.
content
: A string representing the updated file content. Required.
options.message
: A string representing the commit message.
options.newPath
: A string representing the new path to file, if changed.
A string containing the file’s updated URL if successful, else IndiekitError
.
An async function that deletes a file on the content store.
filePath
: A string representing the path to a file. Required.
options.message
: A string representing the commit message.
true
if successful, else IndiekitError
.
Used to register the plug-in. Accepts an Indiekit
instance to allow its modification before returning.
import { IndiekitError } from "@indiekit/error";
import exampleClient from 'example-client';
export default class ExampleStore {
constructor() {
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);
}
}
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"
};
}
Example content store plug-ins:
-
@indiekit/store-github
saves content to a GitHub repository. -
@indiekit/store-file-system
saves content to a directory on a local file system.