diff --git a/src/schemas/registry.test.ts b/src/schemas/registry.test.ts new file mode 100644 index 0000000..a46226c --- /dev/null +++ b/src/schemas/registry.test.ts @@ -0,0 +1,55 @@ +import { describe, it, expect } from 'vitest'; +import { BACKEND_REGISTRY, BackendType } from './registry'; + +const EXPECTED_BACKENDS: BackendType[] = ['azureblob', 's3', 's3-compatible']; + +describe('Backend Schema Registry', () => { + it('exports all three required backend types', () => { + for (const backend of EXPECTED_BACKENDS) { + expect(BACKEND_REGISTRY[backend]).toBeDefined(); + } + }); + + it('each backend has at least one field definition', () => { + for (const backend of EXPECTED_BACKENDS) { + expect(BACKEND_REGISTRY[backend].length).toBeGreaterThan(0); + } + }); + + it('each FieldDef has a non-empty key (snake_case, no camelCase)', () => { + for (const backend of EXPECTED_BACKENDS) { + for (const field of BACKEND_REGISTRY[backend]) { + expect(field.key).toBeTruthy(); + // Reject camelCase — rclone keys are snake_case or lowercase + expect(field.key).not.toMatch(/[A-Z]/); + } + } + }); + + it('each FieldDef has a non-empty label', () => { + for (const backend of EXPECTED_BACKENDS) { + for (const field of BACKEND_REGISTRY[backend]) { + expect(field.label).toBeTruthy(); + } + } + }); + + it('Azure Blob has account field (required)', () => { + const accountField = BACKEND_REGISTRY.azureblob.find(f => f.key === 'account'); + expect(accountField).toBeDefined(); + expect(accountField!.required).toBe(true); + }); + + it('S3 has access_key_id, secret_access_key, and region fields', () => { + const keys = BACKEND_REGISTRY.s3.map(f => f.key); + expect(keys).toContain('access_key_id'); + expect(keys).toContain('secret_access_key'); + expect(keys).toContain('region'); + }); + + it('S3-compatible has endpoint field (required)', () => { + const endpointField = BACKEND_REGISTRY['s3-compatible'].find(f => f.key === 'endpoint'); + expect(endpointField).toBeDefined(); + expect(endpointField!.required).toBe(true); + }); +}); diff --git a/src/schemas/registry.ts b/src/schemas/registry.ts new file mode 100644 index 0000000..f3309ff --- /dev/null +++ b/src/schemas/registry.ts @@ -0,0 +1,112 @@ +// src/schemas/registry.ts +// Backend Schema Registry — single source of truth for all rclone backend field definitions. +// IMPORTANT: FieldDef.key values MUST match rclone config key names exactly. +// These keys are used by Phase 2 generators to build rclone.conf INI content. +// Verify against https://rclone.org/azureblob/ and https://rclone.org/s3/ before Phase 2. + +export type BackendType = 'azureblob' | 's3' | 's3-compatible'; + +export interface FieldDef { + key: string; // MUST match rclone config key exactly (snake_case) + label: string; + inputType: 'text' | 'password' | 'select' | 'toggle'; + required: boolean; + placeholder?: string; + helpText?: string; + options?: { value: string; label: string }[]; // for inputType: 'select' +} + +export const BACKEND_REGISTRY: Record = { + azureblob: [ + { + key: 'account', + label: 'Storage Account Name', + inputType: 'text', + required: true, + placeholder: 'mystorageaccount', + helpText: 'The storage account name (not the full URL)', + }, + { + key: 'key', + label: 'Access Key', + inputType: 'password', + required: false, + helpText: 'Base64-encoded storage account key. Provide either this or a SAS URL, not both.', + }, + { + key: 'sas_url', + label: 'SAS URL', + inputType: 'password', + required: false, + placeholder: 'https://mystorageaccount.blob.core.windows.net/?sv=...', + helpText: 'Full SAS URL including account and container. Provide either this or an access key, not both.', + }, + ], + s3: [ + { + key: 'provider', + label: 'Provider', + inputType: 'select', + required: true, + options: [{ value: 'AWS', label: 'Amazon S3' }], + }, + { + key: 'access_key_id', + label: 'Access Key ID', + inputType: 'text', + required: true, + placeholder: 'AKIAIOSFODNN7EXAMPLE', + }, + { + key: 'secret_access_key', + label: 'Secret Access Key', + inputType: 'password', + required: true, + }, + { + key: 'region', + label: 'Region', + inputType: 'text', + required: true, + placeholder: 'us-east-1', + }, + ], + 's3-compatible': [ + { + key: 'provider', + label: 'Provider', + inputType: 'select', + required: true, + options: [{ value: 'Other', label: 'S3-Compatible' }], + helpText: 'Covers Wasabi, MinIO, Cloudflare R2, and any S3-compatible storage', + }, + { + key: 'access_key_id', + label: 'Access Key ID', + inputType: 'text', + required: true, + }, + { + key: 'secret_access_key', + label: 'Secret Access Key', + inputType: 'password', + required: true, + }, + { + key: 'endpoint', + label: 'Endpoint URL', + inputType: 'text', + required: true, + placeholder: 'https://s3.wasabisys.com', + helpText: 'The S3-compatible endpoint URL for your storage provider', + }, + { + key: 'region', + label: 'Region', + inputType: 'text', + required: false, + placeholder: 'us-east-1', + helpText: 'Optional for most S3-compatible providers', + }, + ], +};