initial-commit
This commit is contained in:
38
.gitignore
vendored
Normal file
38
.gitignore
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
.env
|
||||||
|
node_modules
|
||||||
|
.DS_Store
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
coverage
|
||||||
|
*.local
|
||||||
|
.npmrc
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
|
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Cypress
|
||||||
|
/cypress/videos/
|
||||||
|
/cypress/screenshots/
|
||||||
|
|
||||||
|
# Vitest
|
||||||
|
__screenshots__/
|
||||||
20
README.md
Normal file
20
README.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Taker of Notes Plugin: Browser
|
||||||
|
|
||||||
|
Taker of Notes storage plugin for the browser using IndexedDB
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
1. Install dependencies: `npm install`
|
||||||
|
2. Run tests: `npm test`
|
||||||
|
3. Build: `npm run build`
|
||||||
|
|
||||||
|
## Project Structure
|
||||||
|
|
||||||
|
- `src/` - Source code
|
||||||
|
- `test/` - Tests
|
||||||
|
- `dist/` - Built output
|
||||||
|
- `rollup.config.js` - Build configuration
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
Implement your storage adapter in `src/Browser.js`.
|
||||||
1883
package-lock.json
generated
Normal file
1883
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
28
package.json
Normal file
28
package.json
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"name": "@takerofnotes/plugin-browser",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"repository": {
|
||||||
|
"type": "git"
|
||||||
|
},
|
||||||
|
"type": "module",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "rollup -c",
|
||||||
|
"test": "vitest",
|
||||||
|
"prepublishOnly": "npm run build"
|
||||||
|
},
|
||||||
|
"author": "nicwands",
|
||||||
|
"license": "MIT",
|
||||||
|
"description": "Taker of Notes storage plugin for the browser using IndexedDB",
|
||||||
|
"dependencies": {
|
||||||
|
"@takerofnotes/plugin-sdk": "^0.2.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@rollup/plugin-commonjs": "^29.0.0",
|
||||||
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||||
|
"fake-indexeddb": "^6.2.5",
|
||||||
|
"rollup": "^4.59.0",
|
||||||
|
"vitest": "^4.0.18"
|
||||||
|
}
|
||||||
|
}
|
||||||
13
rollup.config.js
Normal file
13
rollup.config.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
// rollup.config.js
|
||||||
|
import resolve from '@rollup/plugin-node-resolve'
|
||||||
|
import commonjs from '@rollup/plugin-commonjs'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
input: 'src/index.js',
|
||||||
|
output: {
|
||||||
|
file: 'dist/index.js',
|
||||||
|
format: 'esm',
|
||||||
|
sourcemap: true,
|
||||||
|
},
|
||||||
|
plugins: [resolve(), commonjs()],
|
||||||
|
}
|
||||||
91
src/BrowserAdapter.js
Normal file
91
src/BrowserAdapter.js
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
import { BaseNotesAdapter } from '@takerofnotes/plugin-sdk'
|
||||||
|
|
||||||
|
const DB_NAME = 'takerofnotes-browser-db'
|
||||||
|
const DB_VERSION = 1
|
||||||
|
const STORE_NAME = 'notes'
|
||||||
|
|
||||||
|
export default class BrowserAdapter extends BaseNotesAdapter {
|
||||||
|
constructor(config) {
|
||||||
|
super(config)
|
||||||
|
this.db = null
|
||||||
|
}
|
||||||
|
|
||||||
|
async init() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const request = indexedDB.open(DB_NAME, DB_VERSION)
|
||||||
|
|
||||||
|
request.onerror = () => reject(request.error)
|
||||||
|
|
||||||
|
request.onsuccess = () => {
|
||||||
|
this.db = request.result
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
|
||||||
|
request.onupgradeneeded = (event) => {
|
||||||
|
const db = event.target.result
|
||||||
|
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
||||||
|
db.createObjectStore(STORE_NAME, { keyPath: 'id' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAll() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const transaction = this.db.transaction(STORE_NAME, 'readonly')
|
||||||
|
const store = transaction.objectStore(STORE_NAME)
|
||||||
|
const request = store.getAll()
|
||||||
|
|
||||||
|
request.onsuccess = () => resolve(request.result)
|
||||||
|
request.onerror = () => reject(request.error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(note) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const transaction = this.db.transaction(STORE_NAME, 'readwrite')
|
||||||
|
const store = transaction.objectStore(STORE_NAME)
|
||||||
|
const request = store.add(note)
|
||||||
|
|
||||||
|
request.onsuccess = () => resolve()
|
||||||
|
request.onerror = () => reject(request.error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(note) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const transaction = this.db.transaction(STORE_NAME, 'readwrite')
|
||||||
|
const store = transaction.objectStore(STORE_NAME)
|
||||||
|
const request = store.put(note)
|
||||||
|
|
||||||
|
request.onsuccess = () => resolve()
|
||||||
|
request.onerror = () => reject(request.error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(id) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const transaction = this.db.transaction(STORE_NAME, 'readwrite')
|
||||||
|
const store = transaction.objectStore(STORE_NAME)
|
||||||
|
const request = store.delete(id)
|
||||||
|
|
||||||
|
request.onsuccess = () => resolve()
|
||||||
|
request.onerror = () => reject(request.error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async testConnection() {
|
||||||
|
try {
|
||||||
|
const testRequest = indexedDB.open(DB_NAME)
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
testRequest.onsuccess = () => {
|
||||||
|
testRequest.result.close()
|
||||||
|
resolve(true)
|
||||||
|
}
|
||||||
|
testRequest.onerror = () => resolve(false)
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/index.js
Normal file
14
src/index.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { definePlugin } from '@takerofnotes/plugin-sdk'
|
||||||
|
import BrowserAdapter from './BrowserAdapter'
|
||||||
|
|
||||||
|
export default definePlugin({
|
||||||
|
id: 'browser',
|
||||||
|
name: 'Browser',
|
||||||
|
description: 'Taker of Notes storage plugin for the browser using IndexedDB',
|
||||||
|
version: '0.1.0',
|
||||||
|
apiVersion: '0.3.0',
|
||||||
|
configSchema: [],
|
||||||
|
createAdapter(config) {
|
||||||
|
return new BrowserAdapter(config)
|
||||||
|
},
|
||||||
|
})
|
||||||
8
test/plugin.test.js
Normal file
8
test/plugin.test.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { describePluginTests } from '@takerofnotes/plugin-sdk'
|
||||||
|
import plugin from '../src/index.js'
|
||||||
|
|
||||||
|
const adapter = plugin.createAdapter({
|
||||||
|
// Adapter config here
|
||||||
|
})
|
||||||
|
|
||||||
|
describePluginTests({ plugin, adapter }, describe, it, expect)
|
||||||
9
vitest.config.js
Normal file
9
vitest.config.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { defineConfig } from 'vitest/config'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
globals: true,
|
||||||
|
testTimeout: 30000,
|
||||||
|
setupFiles: ['fake-indexeddb/auto'],
|
||||||
|
},
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user