@vperms/sql-adapter
@vperms/sql-adapter is a dialect-agnostic base for SQL-backed adapters. It
implements VeguiPermsAdapter on top of a small SqlAdapterDriver that each
dialect provides.
VeguiPermsSqlAdapter
Section titled “VeguiPermsSqlAdapter”abstract class VeguiPermsSqlAdapter extends VeguiPermsAdapter { protected constructor(driver: SqlAdapterDriver); migrate(): Promise<void>;}migrate() delegates to the driver and must be idempotent. Adapters built on
this class (such as the Drizzle adapters) accept a migrationsFolder option to
override where migration files are read from.
Driver contract
Section titled “Driver contract”interface SqlAdapterDriver { migrate(): Promise<void>; findSubject( workspaceId: string, subjectId: string, ): Promise<SubjectRecord | null>; upsertSubject(record: SubjectRecord): Promise<void>; deleteSubject(workspaceId: string, subjectId: string): Promise<boolean>; findGrants(workspaceId: string, subjectId: string): Promise<GrantRecord[]>; upsertGrant(record: GrantRecord): Promise<void>; deleteGrant( workspaceId: string, subjectId: string, permission: string, ): Promise<boolean>;}Record types
Section titled “Record types”interface SubjectRecord { workspaceId: string; id: string; type: SubjectType; parents: string[];}
interface GrantRecord { workspaceId: string; subjectId: string; permission: string; value: boolean;}These records are the storage representation; they are mapped to and from the
core Subject and PermissionGrant types. See
drizzle-adapter for concrete implementations.