import type { Selectable } from 'kysely'; import type * as Db from '../Db.js'; import type * as db_Schema from '../Schema.js'; /** Columns of the `memberships` table, derived from `Schema.Membership`. */ export type Table = db_Schema.Membership; /** A stored membership row. */ export type Record = Selectable; /** A membership with the member's resolved user identity. */ export type DetailedRecord = Record & { address: string | null; email: string | null; }; /** A membership role. */ export type Role = Record['role']; /** Fixed membership roles, least to most privileged. */ export declare const roles: readonly ["member", "admin", "owner"]; /** Privilege rank per role; higher ranks satisfy lower minimums. */ export declare const rank: { readonly admin: 1; readonly member: 0; readonly owner: 2; }; /** * Inserts a membership and returns the stored record. * * @param db - The database. * @param input - The membership to insert. * @returns The stored record. */ export declare function create(db: Db.Db, input: create.Input): Promise; export declare namespace create { /** Fields accepted when inserting a membership. */ type Input = { /** Organization id (`org_…`). */ orgId: string; /** Granted role. */ role: Role; /** Member user id (`usr_…`). */ userId: string; }; } /** * Reads one user's membership in an organization. * * @param db - The database. * @param orgId - The organization id (`org_…`). * @param userId - The member user id (`usr_…`). * @returns The record, or `undefined` when absent. */ export declare function get(db: Db.Db, orgId: string, userId: string): Promise; /** * Lists an organization's memberships, oldest first (stable member ordering). * * @param db - The database. * @param orgId - The organization id (`org_…`). * @returns The records. */ export declare function listByOrg(db: Db.Db, orgId: string): Promise; /** * Lists an organization's memberships joined with member identity (address, * email), oldest first. * * @param db - The database. * @param orgId - The organization id (`org_…`). * @returns The records with `address`/`email` from the member's user row. */ export declare function listByOrgDetailed(db: Db.Db, orgId: string): Promise; /** * Lists a bounded page of an organization's memberships with member identity, * oldest first. * * @param db - The database. * @param orgId - The organization id. * @param options - Keyset and page-size options. * @returns At most `limit + 1` rows for next-cursor derivation. */ export declare function listByOrgDetailedPage(db: Db.Db, orgId: string, options: listByOrgDetailedPage.Options): Promise; export declare namespace listByOrgDetailedPage { /** Cursor fields for the last membership on the previous page. */ type Cursor = { /** Membership creation time. */ createdAt: string; /** Member user id, used as a deterministic tie-breaker. */ userId: string; }; /** Options for {@link listByOrgDetailedPage}. */ type Options = { /** Last membership returned by the previous page. */ cursor?: Cursor | undefined; /** Requested page size. */ limit: number; }; } /** * Changes a member's role atomically, refusing to demote the last owner. The * org's owner rows are locked for the transaction, so a concurrent demotion or * removal cannot race two guards into leaving the organization ownerless. * * @param db - The database. * @param orgId - The organization id (`org_…`). * @param userId - The member user id (`usr_…`). * @param input - The fields to update. * @returns The updated record, or an `error` when absent or the last owner. */ export declare function update(db: Db.Db, orgId: string, userId: string, input: update.Input): Promise; export declare namespace update { /** Mutable membership fields. */ type Input = { /** New role. */ role: Role; }; /** Outcome of a guarded role change. */ type Result = { error: 'last_owner' | 'not_found'; record?: undefined; } | { error?: undefined; record: Record; }; } /** * Deletes a membership atomically, refusing to remove the last owner. Locks * the org's owner rows for the transaction (see {@link update}) so concurrent * removals cannot race the organization ownerless. * * @param db - The database. * @param orgId - The organization id (`org_…`). * @param userId - The member user id (`usr_…`). * @returns `removed` on success, otherwise why the removal was refused. */ export declare function remove(db: Db.Db, orgId: string, userId: string): Promise; export declare namespace remove { /** Outcome of a guarded removal. */ type Result = 'last_owner' | 'not_found' | 'removed'; } //# sourceMappingURL=memberships.d.ts.map