|
| 1 | +import makeDebug from "debug"; |
| 2 | + |
| 3 | +import { IndiekitPlugin } from "./base.js"; |
| 4 | + |
| 5 | +const debug = makeDebug(`indiekit:plugin`); |
| 6 | + |
| 7 | +/** |
| 8 | + * @typedef StoreInformation |
| 9 | + * @property {string} name - Name of content store |
| 10 | + * @property {string} uid - Unique identifier |
| 11 | + */ |
| 12 | + |
| 13 | +/** |
| 14 | + * Content store plug-in |
| 15 | + * @class |
| 16 | + * @augments {IndiekitPlugin} |
| 17 | + */ |
| 18 | +export class IndiekitStorePlugin extends IndiekitPlugin { |
| 19 | + /** |
| 20 | + * Content store information |
| 21 | + * @type {StoreInformation} |
| 22 | + */ |
| 23 | + info = undefined; |
| 24 | + |
| 25 | + /** |
| 26 | + * Create file |
| 27 | + * @param {string} filePath - Path to file |
| 28 | + * @returns {Promise<string>} Created file URL |
| 29 | + */ |
| 30 | + async createFile(filePath) { |
| 31 | + debug(`Creating ${filePath} to ${this.name}`); |
| 32 | + return; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Read file |
| 37 | + * @param {string} filePath - Path to file |
| 38 | + * @returns {Promise<string>} File content |
| 39 | + */ |
| 40 | + async readFile(filePath) { |
| 41 | + debug(`Reading ${filePath} at ${this.name}`); |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Update file |
| 47 | + * @param {string} filePath - Path to file |
| 48 | + * @returns {Promise<string>} Updated file URL |
| 49 | + */ |
| 50 | + async updateFile(filePath) { |
| 51 | + debug(`Updating ${filePath} at ${this.name}`); |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Delete file |
| 57 | + * @param {string} filePath - Path to file |
| 58 | + * @returns {Promise<boolean>} File deleted |
| 59 | + */ |
| 60 | + async deleteFile(filePath) { |
| 61 | + debug(`Creating ${filePath} to ${this.name}`); |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + #addStore() { |
| 66 | + debug(`Adding content store: ${this.name}`); |
| 67 | + this.indiekit.stores.add(this); |
| 68 | + } |
| 69 | + |
| 70 | + async init() { |
| 71 | + await super.init(); |
| 72 | + |
| 73 | + this.#addStore(); |
| 74 | + } |
| 75 | +} |
0 commit comments