@samveys/admin

Layar CRUD yang dirender server, diperiksa policy dan diaudit untuk model ORM

Versi
1.0.35 Nov 2026
Pasang
pnpm add @samveys/admin
Dokumentasi
README paket ini

Daftar ini dibaca dari versi 1.0.2; jalankan pnpm sync untuk memperbaruinya.

Import
import { admin, createAuditLog, resource, DEFAULT_AUDIT_TABLE, DEFAULT_PER_PAGE, MAX_PER_PAGE } from '@samveys/admin'

Fungsi (3)

admin Fungsi

The `@samveys/admin` plugin: `admin({ path: '/admin', resources: [resource(Post, { … })] })`.

function admin(options: AdminOptions): import("@samveys/core").Plugin<AdminOptions>;

Diekspor dari packages/admin/src/plugin.ts

createAuditLog Fungsi

The audit log: a table created on first use through the `'db'` binding.

function createAuditLog(container: Container, table?: string): AuditLog;

Diekspor dari packages/admin/src/audit.ts

resource Fungsi

Declares one model in the panel. Pass the result in `admin({ resources: [...] })`.

function resource(model: AdminResource['model'], options: ResourceOptions): AdminResource;

Diekspor dari packages/admin/src/plugin.ts

Nilai (3)

DEFAULT_AUDIT_TABLE Nilai

Tidak ada komentar dokumentasi.

const DEFAULT_AUDIT_TABLE = "samveys_admin_audit";

Diekspor dari packages/admin/src/audit.ts

DEFAULT_PER_PAGE Nilai

Default page size of the list screen.

const DEFAULT_PER_PAGE = 25;

Diekspor dari packages/admin/src/contracts.ts

MAX_PER_PAGE Nilai

Largest page size the list screen accepts.

const MAX_PER_PAGE = 100;

Diekspor dari packages/admin/src/contracts.ts

Interface (8)

AdminOptions Interface

Tidak ada komentar dokumentasi.

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;
}

Diekspor dari packages/admin/src/contracts.ts

AdminResource Interface

A model registered with `resource(Model, options)`.

interface AdminResource {
    readonly model: ModelCtor;
    readonly options: ResourceOptions;
}

Diekspor dari 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;
        }>;
    };
}

Diekspor dari 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[];
}

Diekspor dari packages/admin/src/contracts.ts

AuditLog Interface

Tidak ada komentar dokumentasi.

interface AuditLog {
    record(entry: AuditRecord): Promise<void>;
    list(): Promise<AuditEntry[]>;
}

Diekspor dari packages/admin/src/audit.ts

AuditRecord Interface

Tidak ada komentar dokumentasi.

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[];
}

Diekspor dari 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;
}

Diekspor dari packages/admin/src/contracts.ts

ResourceOptions Interface

Tidak ada komentar dokumentasi.

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;
  …
Tampilkan seluruh deklarasi (27 baris)
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[];
}

Diekspor dari packages/admin/src/contracts.ts

Tipe (3)

AdminAction Tipe

The five actions every admin route is checked against before it reads or writes.

type AdminAction = 'viewAny' | 'view' | 'create' | 'update' | 'delete';

Diekspor dari packages/admin/src/contracts.ts

FieldErrors Tipe

Per-field validation messages, shown next to their field.

type FieldErrors = Readonly<Record<string, string>>;

Diekspor dari packages/admin/src/contracts.ts

FieldKind Tipe

HTML input kinds the form generator can emit.

type FieldKind = 'text' | 'textarea' | 'checkbox' | 'number' | 'datetime-local' | 'select';

Diekspor dari packages/admin/src/contracts.ts