3 Commits
v0.1.1 ... main

Author SHA1 Message Date
nicwands
406f8ddb74 0.2.0 2026-03-02 11:58:01 -05:00
nicwands
cf8574664f remove md test files 2026-03-02 11:57:56 -05:00
nicwands
036a19bf88 update adapter to encrypted format 2026-03-02 11:57:30 -05:00
10 changed files with 1165 additions and 121 deletions

1193
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "@takerofnotes/plugin-filesystem", "name": "@takerofnotes/plugin-filesystem",
"version": "0.1.1", "version": "0.2.0",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/nicwands/takerofnotes-plugin-filesystem.git" "url": "git+https://github.com/nicwands/takerofnotes-plugin-filesystem.git"
@@ -10,18 +10,19 @@
"exports": "./dist/index.js", "exports": "./dist/index.js",
"scripts": { "scripts": {
"build": "rollup -c", "build": "rollup -c",
"test": "vitest",
"prepublishOnly": "npm run build" "prepublishOnly": "npm run build"
}, },
"author": "nicwands", "author": "nicwands",
"license": "MIT", "license": "MIT",
"description": "Filesystem storage plugin for Taker of Notes", "description": "Filesystem storage plugin for Taker of Notes",
"dependencies": { "dependencies": {
"@takerofnotes/plugin-sdk": "^0.1.0", "@takerofnotes/plugin-sdk": "^0.3.1"
"gray-matter": "^4.0.3"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-commonjs": "^29.0.0", "@rollup/plugin-commonjs": "^29.0.0",
"@rollup/plugin-node-resolve": "^16.0.3", "@rollup/plugin-node-resolve": "^16.0.3",
"rollup": "^4.59.0" "rollup": "^4.59.0",
"vitest": "^3.0.0"
} }
} }

View File

@@ -1,5 +1,4 @@
import { BaseNotesAdapter } from '@takerofnotes/plugin-sdk' import { BaseNotesAdapter } from '@takerofnotes/plugin-sdk'
import matter from 'gray-matter'
import fs from 'fs/promises' import fs from 'fs/promises'
import path from 'path' import path from 'path'
@@ -21,16 +20,13 @@ export default class FileSystemAdapter extends BaseNotesAdapter {
const notes = [] const notes = []
for (const file of files) { for (const file of files) {
if (!file.endsWith('.md')) continue if (!file.endsWith('.json')) continue
const fullPath = path.join(this.notesDir, file) const fullPath = path.join(this.notesDir, file)
const raw = await fs.readFile(fullPath, 'utf8') const fileContent = await fs.readFile(fullPath, 'utf8')
const parsed = matter(raw) const parsedFile = JSON.parse(fileContent)
notes.push({ notes.push(parsedFile)
...parsed.data,
content: parsed.content,
})
} }
return notes return notes
@@ -45,21 +41,15 @@ export default class FileSystemAdapter extends BaseNotesAdapter {
} }
async delete(id) { async delete(id) {
const filePath = path.join(this.notesDir, `${id}.md`) const filePath = path.join(this.notesDir, `${id}.json`)
await fs.unlink(filePath) await fs.unlink(filePath)
} }
async _write(note) { async _write(note) {
const filePath = path.join(this.notesDir, `${note.id}.md`) const filePath = path.join(this.notesDir, `${note.id}.json`)
const fileContent = matter.stringify(note.content, { const stringifiedNote = JSON.stringify(note)
id: note.id,
title: note.title,
category: note.category ?? null,
createdAt: note.createdAt,
updatedAt: note.updatedAt,
})
await fs.writeFile(filePath, fileContent, 'utf8') await fs.writeFile(filePath, stringifiedNote, 'utf8')
} }
} }

View File

@@ -6,7 +6,7 @@ export default definePlugin({
name: 'Filesystem', name: 'Filesystem',
description: 'Store notes as markdown files on your local filesystem', description: 'Store notes as markdown files on your local filesystem',
version: '0.1.0', version: '0.1.0',
apiVersion: '0.1.0', apiVersion: '0.3.1',
configSchema: [ configSchema: [
{ {
key: 'notesDir', key: 'notesDir',

45
test/plugin.test.js Normal file
View File

@@ -0,0 +1,45 @@
import { describe, it } from 'vitest'
import { runPluginTests } from '@takerofnotes/plugin-sdk'
import plugin from './src/index.js'
import FileSystemAdapter from './src/FileSystemAdapter.js'
import path from 'path'
import { fileURLToPath } from 'url'
import fs from 'fs'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const testDir = path.join(__dirname, 'test-notes')
if (!fs.existsSync(testDir)) {
fs.mkdirSync(testDir, { recursive: true })
}
const adapter = new FileSystemAdapter({ notesDir: testDir })
const tests = runPluginTests({ plugin, adapter })
describe('Plugin Validation', () => {
tests.validatePlugin(it, (a, b) => expect(a).toBe(b))
})
describe('Adapter: init()', () => {
tests.init(it)
})
describe('Adapter: getAll()', () => {
tests.getAll(it)
})
describe('Adapter: create()', () => {
tests.create(it)
})
describe('Adapter: update()', () => {
tests.update(it)
})
describe('Adapter: delete()', () => {
tests.delete(it)
})
describe('Full CRUD Cycle', () => {
tests.crudCycle(it)
})

View File

@@ -0,0 +1 @@
{"id":"test-create-note","data":"test-data"}

View File

@@ -0,0 +1 @@
{"id":"test-note-1","data":"test-data"}

View File

@@ -0,0 +1 @@
{"id":"test-update-note-2","data":"Updated data v2"}

View File

@@ -0,0 +1 @@
{"id":"test-update-note","data":"Updated data"}

7
vitest.config.js Normal file
View File

@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
globals: true,
},
})