Add READMEs for remaining packages

- db-schema: Database schema types from kysely-codegen
- db: Database client and helper functions
- testing: Overview of testing packages
- test-helpers: Database testing utilities
- virtual-authenticator: WebAuthn virtual authenticator

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
igm
2026-01-12 13:59:34 +08:00
parent 26d10d452f
commit 01f1e1c9e3
5 changed files with 182 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
# @reviq/db-schema
Database schema types generated from PostgreSQL using kysely-codegen.
## Usage
```typescript
import type { Database } from "@reviq/db-schema";
```
## Regenerating Types
When the database schema changes, regenerate the types:
```bash
bun run --cwd packages/db-schema generate
```
This requires `DATABASE_URL` to be set and pointing to a database with the current schema.
## Exports
- `Database` - The full database type for use with Kysely
- Table types for all database tables (e.g., `Users`, `Orgs`, `Sessions`)

33
packages/db/README.md Normal file
View File

@@ -0,0 +1,33 @@
# @reviq/db
Database client and helper functions for the RevIQ platform.
## Usage
```typescript
import { createDb } from "@reviq/db";
const db = createDb(process.env.DATABASE_URL);
// Use db with Kysely queries
const users = await db.selectFrom("users").selectAll().execute();
// Clean up when done
await db.destroy();
```
## Exports
### Client
- `createDb(url)` - Create a Kysely database instance
### Helper Functions
- `executeBootstrap(trx, input)` - Bootstrap a new database with superuser and org
- `generateToken()` - Generate an API token
- `hashToken(token)` - Hash a token for storage
- `parseToken(token)` - Parse and validate a token
- `TOKEN_PREFIX` - The `reviq_` prefix for API tokens
### Types
- `Database` - Re-exported from `@reviq/db-schema`
- `BootstrapInput` / `BootstrapResult` - Types for bootstrap operation

View File

@@ -0,0 +1,34 @@
# Testing Packages
Shared testing utilities for the RevIQ platform.
## Packages
### @reviq/test-helpers
Database testing utilities including test database setup, transactions, and fixtures.
```typescript
import { createTestDb, withTestTransaction, describeE2E } from "@reviq/test-helpers";
```
### @reviq/virtual-authenticator
WebAuthn virtual authenticator for testing passkey flows without real hardware.
```typescript
import { VirtualAuthenticator } from "@reviq/virtual-authenticator";
```
## Usage
These packages are used internally for e2e and integration tests. Add them as dev dependencies:
```json
{
"devDependencies": {
"@reviq/test-helpers": "workspace:*",
"@reviq/virtual-authenticator": "workspace:*"
}
}
```

View File

@@ -0,0 +1,52 @@
# @reviq/test-helpers
Database testing utilities for integration and e2e tests.
## Usage
```typescript
import {
describeE2E,
createTestDb,
withTestTransaction,
createTestUser,
} from "@reviq/test-helpers";
describeE2E("My API tests", () => {
it("should create a user", async () => {
await withTestTransaction(async (trx) => {
const user = await createTestUser(trx, {
email: "test@example.com",
});
expect(user.id).toBeDefined();
});
});
});
```
## Exports
### Test Setup
- `describeE2E(name, fn)` - Wrapper for describe() that skips when `SKIP_DB_TESTS=1`
- `SKIP_DB_TESTS` - Boolean indicating if db tests should be skipped
### Database Utilities
- `createTestDb()` - Create an isolated test database
- `destroyTestDb(db)` - Destroy a test database
- `getSharedDb()` - Get the shared test database instance
- `destroySharedDb()` - Destroy the shared database
- `initTestDb()` - Initialize the test database
- `runMigrations(url)` - Run database migrations
- `truncateAllTables(db)` - Clear all data from tables
- `getTestDatabaseUrl()` - Get the test database connection URL
### Transaction Helpers
- `withTestTransaction(fn)` - Run a function in a rolled-back transaction
### Fixtures
- `createTestUser(trx, opts)` - Create a test user
### Constants
- `TEST_RP` - Test relying party configuration for WebAuthn
- `DEFAULT_TEST_AAGUID` - Default AAGUID for virtual authenticator
- `KNOWN_AAGUIDS` - Map of known authenticator AAGUIDs

View File

@@ -0,0 +1,39 @@
# @reviq/virtual-authenticator
WebAuthn virtual authenticator for testing passkey registration and authentication flows.
## Usage
```typescript
import { VirtualAuthenticator } from "@reviq/virtual-authenticator";
const authenticator = new VirtualAuthenticator({
aaguid: "00000000-0000-0000-0000-000000000000",
});
// Create a credential during registration
const credential = await authenticator.create(
publicKeyCredentialCreationOptions,
);
// Use the credential during authentication
const assertion = await authenticator.get(
publicKeyCredentialRequestOptions,
);
```
## Exports
### Classes
- `VirtualAuthenticator` - Simulates a WebAuthn authenticator
### Utilities
- `base64urlToUint8Array(str)` - Decode base64url to bytes
- `uint8ArrayToBase64url(bytes)` - Encode bytes to base64url
- `parseAaguid(str)` - Parse an AAGUID string to bytes
### Constants
- `DEFAULT_AAGUID` - Default AAGUID for the virtual authenticator
### Types
- `VirtualAuthenticatorOptions` - Configuration options for the authenticator