Rowguard - RLS Policy DSL - v0.2.0
    Preparing search index...

    Interface TypedRowguard<DB>

    Typed Rowguard instance with schema-aware API

    interface TypedRowguard<DB> {
        policy(
            name: string,
        ): { on<T extends never>(table: T): TypedPolicyBuilder<DB, T> };
        column<T extends never, C extends never>(
            table: T,
            column: C,
        ): TypedColumnBuilder<ColumnType<DB, T, C>>;
        auth: { uid(): ContextValue };
        session: { get(key: string, type: SessionVariableType): ContextValue };
    }

    Type Parameters

    • DB
    Index

    Properties

    Methods

    Properties

    auth: { uid(): ContextValue }

    Auth context helpers

    Type Declaration

    • uid: function
      • Returns current authenticated user ID

        Maps to auth.uid() in PostgreSQL (commonly used with Supabase). This returns the user ID from the JWT token.

        Returns ContextValue

        A ContextValue representing the current user's ID

        // Basic user ownership
        column('user_id').eq(auth.uid())

        // In a policy
        policy('user_documents')
        .on('documents')
        .read()
        .when(column('user_id').eq(auth.uid()));

        // With complex conditions
        policy('project_access')
        .on('projects')
        .read()
        .when(
        column('created_by').eq(auth.uid())
        .or(column('is_public').eq(true))
        );
    session: { get(key: string, type: SessionVariableType): ContextValue }

    Session variable helpers

    Type Declaration

    • get: function
      • Get a session variable with type casting

        Maps to current_setting(key)::TYPE in PostgreSQL.

        Parameters

        • key: string

          Session variable key (e.g., 'app.current_tenant_id')

        • type: SessionVariableType

          Type to cast to ('integer', 'uuid', 'boolean', 'timestamp', or 'text')

        Returns ContextValue

        A ContextValue representing the session variable

        // Integer session variable
        column('tenant_id').eq(session.get('app.tenant_id', 'integer'))

        // UUID session variable
        column('org_id').eq(session.get('app.org_id', 'uuid'))

        // Boolean session variable
        column('is_admin').eq(session.get('app.is_admin', 'boolean'))

        // Text session variable (default)
        column('role').eq(session.get('app.role', 'text'))

    Methods