@samveys/admin
Server-rendered, policy-checked and audited CRUD screens for ORM models
This list was read from version 1.0.2; run pnpm sync to refresh it.
import { admin, createAuditLog, resource, DEFAULT_AUDIT_TABLE, DEFAULT_PER_PAGE, MAX_PER_PAGE } from '@samveys/admin'
Function (3)
admin
Function
The `@samveys/admin` plugin: `admin({ path: '/admin', resources: [resource(Post, { … })] })`.
function admin(options: AdminOptions): import("@samveys/core").Plugin<AdminOptions>;
Exported from packages/admin/src/plugin.ts
createAuditLog
Function
The audit log: a table created on first use through the `'db'` binding.
function createAuditLog(container: Container, table?: string): AuditLog;
Exported from packages/admin/src/audit.ts
resource
Function
Declares one model in the panel. Pass the result in `admin({ resources: [...] })`.
function resource(model: AdminResource['model'], options: ResourceOptions): AdminResource;
Exported from packages/admin/src/plugin.ts
Value (3)
DEFAULT_AUDIT_TABLE
Value
No documentation comment.
const DEFAULT_AUDIT_TABLE = "samveys_admin_audit";
Exported from packages/admin/src/audit.ts
DEFAULT_PER_PAGE
Value
Default page size of the list screen.
const DEFAULT_PER_PAGE = 25;
Exported from packages/admin/src/contracts.ts
MAX_PER_PAGE
Value
Largest page size the list screen accepts.
const MAX_PER_PAGE = 100;
Exported from packages/admin/src/contracts.ts
Interface (8)
AdminOptions
Interface
No documentation comment.
interface AdminOptions {
/** Mount path of the panel. Default `/admin`. */
readonly path?: string;
readonly resources: readonly AdminResource[];
/** Audit table name. Default `samveys_admin_audit`. */
readonly auditTable?: string;
}
Exported from packages/admin/src/contracts.ts
AdminResource
Interface
A model registered with `resource(Model, options)`.
interface AdminResource {
readonly model: ModelCtor;
readonly options: ResourceOptions;
}
Exported from packages/admin/src/contracts.ts
AdminSearch
Interface
Optional full-text search, shaped like `searchable(...)` from `@samveys/search`.
interface AdminSearch {
/** Returns one page of records whose text matches `text`. */
search(text: string): {
paginate(page: number, perPage: number): Promise<{
readonly data: readonly unknown[];
readonly total: number;
}>;
};
}
Exported from packages/admin/src/contracts.ts
AuditEntry
Interface
One row of the audit log: field names only, never values.
interface AuditEntry {
readonly id: string;
readonly at: string;
readonly userId: string;
readonly resource: string;
readonly recordId: string;
readonly action: 'create' | 'update' | 'delete';
readonly fields: readonly string[];
}
Exported from packages/admin/src/contracts.ts
AuditLog
Interface
No documentation comment.
interface AuditLog {
record(entry: AuditRecord): Promise<void>;
list(): Promise<AuditEntry[]>;
}
Exported from packages/admin/src/audit.ts
AuditRecord
Interface
No documentation comment.
interface AuditRecord {
readonly userId: string;
readonly resource: string;
readonly recordId: string;
readonly action: AuditEntry['action'];
/** Attribute NAMES that were written or changed. Values are never recorded. */
readonly fields: readonly string[];
}
Exported from packages/admin/src/audit.ts
FieldSpec
Interface
A form field after it was derived from a column.
interface FieldSpec {
readonly name: string;
readonly kind: FieldKind;
readonly required: boolean;
/** True when the column accepts NULL; a blank input then stores NULL, otherwise the column default applies. */
readonly nullable: boolean;
readonly options?: readonly string[];
readonly secret: boolean;
}
Exported from packages/admin/src/contracts.ts
ResourceOptions
Interface
No documentation comment.
interface ResourceOptions {
/** URL segment under the panel path. Default: the model's table name. */
readonly name?: string;
/** Heading shown on the screens. Default: `name`. */
readonly label?: string;
/**
* Rules for `viewAny`, `view`, `create`, `update` and `delete`. Default `{}`: every action is
* denied (deny by default). A rule gets the signed-in user and the record (or `undefined`).
*/
readonly policy?: Policy;
…
Show the whole declaration (27 lines)
interface ResourceOptions {
/** URL segment under the panel path. Default: the model's table name. */
readonly name?: string;
/** Heading shown on the screens. Default: `name`. */
readonly label?: string;
/**
* Rules for `viewAny`, `view`, `create`, `update` and `delete`. Default `{}`: every action is
* denied (deny by default). A rule gets the signed-in user and the record (or `undefined`).
*/
readonly policy?: Policy;
…interface ResourceOptions {
/** URL segment under the panel path. Default: the model's table name. */
readonly name?: string;
/** Heading shown on the screens. Default: `name`. */
readonly label?: string;
/**
* Rules for `viewAny`, `view`, `create`, `update` and `delete`. Default `{}`: every action is
* denied (deny by default). A rule gets the signed-in user and the record (or `undefined`).
*/
readonly policy?: Policy;
/** Attributes shown in the list and on the show screen. Nothing outside this list is ever rendered (allow list). */
readonly columns: readonly string[];
/** Attributes the create and edit forms show and accept. A posted attribute outside this list is dropped. */
readonly fields: readonly string[];
/** Attributes the list may be sorted by. A `sort` outside this list is ignored. Default none. */
readonly sortable?: readonly string[];
/** Text attributes searched with `LIKE` when `search` is not set. Default none (no search box). */
readonly searchable?: readonly string[];
/** Full-text search used instead of `LIKE`. */
readonly search?: AdminSearch;
/** Page size, capped at {@link MAX_PER_PAGE}. Default {@link DEFAULT_PER_PAGE}. */
readonly perPage?: number;
/** Allowed values of an enum attribute; makes its form control a select. */
readonly enums?: Readonly<Record<string, readonly string[]>>;
/** Attributes whose values are never rendered; the form shows a blank password-style input and an empty value is not written. */
readonly secret?: readonly string[];
}
Exported from packages/admin/src/contracts.ts
Type (3)
AdminAction
Type
The five actions every admin route is checked against before it reads or writes.
type AdminAction = 'viewAny' | 'view' | 'create' | 'update' | 'delete';
Exported from packages/admin/src/contracts.ts
FieldErrors
Type
Per-field validation messages, shown next to their field.
type FieldErrors = Readonly<Record<string, string>>;
Exported from packages/admin/src/contracts.ts
FieldKind
Type
HTML input kinds the form generator can emit.
type FieldKind = 'text' | 'textarea' | 'checkbox' | 'number' | 'datetime-local' | 'select';
Exported from packages/admin/src/contracts.ts