initial-commit
This commit is contained in:
36
.gitignore
vendored
Normal file
36
.gitignore
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
.DS_Store
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
coverage
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
|
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Cypress
|
||||||
|
/cypress/videos/
|
||||||
|
/cypress/screenshots/
|
||||||
|
|
||||||
|
# Vitest
|
||||||
|
__screenshots__/
|
||||||
1485
package-lock.json
generated
Normal file
1485
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
package.json
Normal file
30
package.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"name": "@takerofnotes/plugin-sdk",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "SDK to create a storage plugin for Taker of Notes",
|
||||||
|
"type": "module",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"types": "dist/index.d.ts",
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"import": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsup src/index.ts --format esm --dts",
|
||||||
|
"dev": "tsup src/index.ts --format esm --dts --watch"
|
||||||
|
},
|
||||||
|
"author": "nicwands",
|
||||||
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"tsup": "^8.5.1",
|
||||||
|
"typescript": "^5.9.3"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"zod": "^4.3.6"
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/BaseNotesAdapter.ts
Normal file
13
src/BaseNotesAdapter.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
export abstract class BaseNotesAdapter {
|
||||||
|
config: any
|
||||||
|
|
||||||
|
constructor(config: any = {}) {
|
||||||
|
this.config = config
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract init(): Promise<void>
|
||||||
|
abstract getAll(): Promise<any[]>
|
||||||
|
abstract create(note: any): Promise<void>
|
||||||
|
abstract update(note: any): Promise<void>
|
||||||
|
abstract delete(id: string): Promise<void>
|
||||||
|
}
|
||||||
6
src/definePlugin.ts
Normal file
6
src/definePlugin.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { validatePlugin } from './validatePlugin'
|
||||||
|
import type { NotesPlugin } from './types'
|
||||||
|
|
||||||
|
export const definePlugin = (plugin: NotesPlugin): NotesPlugin => {
|
||||||
|
return validatePlugin(plugin)
|
||||||
|
}
|
||||||
4
src/index.ts
Normal file
4
src/index.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export { BaseNotesAdapter } from './BaseNotesAdapter'
|
||||||
|
export { definePlugin } from './definePlugin'
|
||||||
|
export { validatePlugin, SUPPORTED_API_VERSION } from './validatePlugin'
|
||||||
|
export type { NotesPlugin, ConfigField } from './types'
|
||||||
17
src/types.ts
Normal file
17
src/types.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
export interface ConfigField {
|
||||||
|
key: string
|
||||||
|
label: string
|
||||||
|
type: 'text' | 'password' | 'directory' | 'number' | 'boolean'
|
||||||
|
default: 'text' | 'password' | 'directory' | 'number' | 'boolean'
|
||||||
|
required?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NotesPlugin {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
description: string
|
||||||
|
version: string
|
||||||
|
apiVersion: string
|
||||||
|
configSchema: ConfigField[]
|
||||||
|
createAdapter(config: any): any
|
||||||
|
}
|
||||||
33
src/validatePlugin.ts
Normal file
33
src/validatePlugin.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
export const SUPPORTED_API_VERSION = '0.1.0'
|
||||||
|
|
||||||
|
const ConfigFieldSchema = z.object({
|
||||||
|
key: z.string(),
|
||||||
|
label: z.string(),
|
||||||
|
type: z.enum(['text', 'password', 'directory', 'number', 'boolean']),
|
||||||
|
default: z.enum(['text', 'password', 'directory', 'number', 'boolean']),
|
||||||
|
required: z.boolean().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const PluginSchema = z.object({
|
||||||
|
id: z.string(),
|
||||||
|
name: z.string(),
|
||||||
|
description: z.string(),
|
||||||
|
version: z.string(),
|
||||||
|
apiVersion: z.string(),
|
||||||
|
configSchema: z.array(ConfigFieldSchema),
|
||||||
|
createAdapter: z.function(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const validatePlugin = (plugin: unknown) => {
|
||||||
|
const parsed = PluginSchema.parse(plugin)
|
||||||
|
|
||||||
|
if (parsed.apiVersion !== SUPPORTED_API_VERSION) {
|
||||||
|
throw new Error(
|
||||||
|
`Plugin API mismatch. Expected ${SUPPORTED_API_VERSION}`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
13
tsconfig.json
Normal file
13
tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2020",
|
||||||
|
"module": "ESNext",
|
||||||
|
"declaration": true,
|
||||||
|
"outDir": "dist",
|
||||||
|
"strict": true,
|
||||||
|
"moduleResolution": "Node",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user