initial-commit
This commit is contained in:
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
|
||||
}
|
||||
Reference in New Issue
Block a user