Files
member-console/internal/entitlements/querier.go
T
cgalo5758 257955c9d3 Add operator list-scale contract and People directory
Governed operator lists (organizations, grants, people, billing×4) gain
server-side search, status filters, and 50-row pages with true totals
from count(*) OVER(); state is URL-addressable, out-of-range pages
clamp,
and no-match is distinct from true-empty.

People is the eighth flat sidebar entry: /operator/persons lists persons
newest-joined first (excluding the reserved system person), rows linking
to the existing detail.

Billing gains an operator invoice detail at
/operator/billing/invoices/{invoiceID} reusing the member projection;
open invoices past due present as Overdue (derived, filterable, stored
status untouched); all four views lead with the linked organization and
mute object IDs.

Grants filter over the derived Live/Superseded/Inactive state, the SQL
HAVING predicate pinned to the Go derivation by test. Embedded lists
(org composite ledger, Tier changes) adopt the shared controls under
namespaced params with sibling-state-preserving URLs and scoped htmx
swaps that hold the viewport.

Review corrections: blocked ladder Delete renders disabled with tooltip
and mutations fire toasts; collapse triggers paint their open state;
sections use outside headings; plan topology drops the orphan-product
check; domains policy collapses behind a disclosure.
2026-08-24 03:58:18 -05:00

235 lines
16 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
package entitlements
import (
"context"
"database/sql"
"github.com/google/uuid"
)
type Querier interface {
// Setup-checklist existence probe: the whole-table answer, not a lookup.
AnyActiveEntitlementSet(ctx context.Context) (bool, error)
// Empty-validation-domain probe: the topology health strip claims health
// only when at least one active attachment existed for the checks to cover.
AnyActiveLadderAttachment(ctx context.Context) (bool, error)
AtomicDecrementUsage(ctx context.Context, arg AtomicDecrementUsageParams) (sql.Result, error)
AtomicIncrementUsage(ctx context.Context, arg AtomicIncrementUsageParams) (sql.Result, error)
CountActiveAttachmentsByLadder(ctx context.Context, planLadderID string) (int64, error)
CountActiveAttachmentsByTier(ctx context.Context, arg CountActiveAttachmentsByTierParams) (int64, error)
// The delivering-grants caption: how many signup defaults are delivering,
// excluded from the headline above. Same provision join as
// CountDeliveringOperatorGrants so the two can never disagree about what
// "delivering" means.
CountDeliveringDefaultGrants(ctx context.Context) (int64, error)
// Operator overview headline: grants someone deliberately issued that are
// delivering right now. Signup defaults are excluded — conferral mints one
// per org, so they drown the number an operator can act on; their count
// rides the tile's caption (CountDeliveringDefaultGrants). Non-default is
// exactly the operator-authored set per chk_grants_default_iff_system_authored.
//
// grants.status is an issuance LEDGER — it records what was written and
// whether it was later revoked, not whether service is flowing today. The
// current-delivery fact lives on core.pool_provisions.status, so this counts
// distinct grants that own at least one active provision rather than
// filtering grants.status alone.
CountDeliveringOperatorGrants(ctx context.Context) (int64, error)
CreateEntitlementSet(ctx context.Context, arg CreateEntitlementSetParams) (EntitlementSet, error)
CreateEntitlementSetRule(ctx context.Context, arg CreateEntitlementSetRuleParams) (EntitlementSetRule, error)
CreateGrant(ctx context.Context, arg CreateGrantParams) (Grant, error)
CreateNumericEntitlement(ctx context.Context, arg CreateNumericEntitlementParams) (NumericEntitlement, error)
CreateNumericEntitlementContribution(ctx context.Context, arg CreateNumericEntitlementContributionParams) (NumericEntitlementContribution, error)
CreateNumericEntitlementUsage(ctx context.Context, arg CreateNumericEntitlementUsageParams) (NumericEntitlementUsage, error)
CreatePoolAssignment(ctx context.Context, arg CreatePoolAssignmentParams) (PoolAssignment, error)
CreateResourcePool(ctx context.Context, arg CreateResourcePoolParams) (ResourcePool, error)
DeleteContributionsByProvisionID(ctx context.Context, provisionID string) error
DeleteEntitlementSetRule(ctx context.Context, ruleID string) error
// Marks a grant expired at its valid_until bound. Enacting the position end is
// end_conferral's job; this is the decree half (design D5).
ExpireGrant(ctx context.Context, grantID string) (Grant, error)
GetActiveAttachmentsByPool(ctx context.Context, poolID string) ([]PoolProvisionLadder, error)
// Writes to core.pool_provision_ladders go through the conferral functions
// (queries/conferral.sql) alone; core_writer holds no direct DML on this
// table (migration 00005 enclosure). Only read paths live here.
GetActiveLadderAttachmentByPoolLadder(ctx context.Context, arg GetActiveLadderAttachmentByPoolLadderParams) (PoolProvisionLadder, error)
GetActivePoolProvisionsByPoolID(ctx context.Context, poolID string) ([]PoolProvision, error)
GetActiveRulesBySetID(ctx context.Context, setID string) ([]EntitlementSetRule, error)
GetBooleanEntitlementByPoolAndResource(ctx context.Context, arg GetBooleanEntitlementByPoolAndResourceParams) (BooleanEntitlement, error)
GetDefaultPoolByOrgID(ctx context.Context, orgID string) (ResourcePool, error)
GetEntitlementSetByID(ctx context.Context, setID string) (EntitlementSet, error)
GetGrantByID(ctx context.Context, grantID string) (Grant, error)
// Walks the ancestry chain of the focal grant via extends_grant_id, returning
// the focal grant first followed by each ancestor (parent, grandparent, ...)
// in chain-walk order. Revoked or expired ancestors are included; lineage is
// about who-came-before, not current validity.
GetGrantLineage(ctx context.Context, grantID string) ([]GetGrantLineageRow, error)
GetLadderAttachmentsByPool(ctx context.Context, poolID string) ([]PoolProvisionLadder, error)
GetLadderAttachmentsByProvision(ctx context.Context, provisionID string) ([]PoolProvisionLadder, error)
// Live (active|suspended) plan-ladder attachments for a pool together with
// their source provenance, for the org-type default-change classification:
// a grant-sourced row with grant_reason = 'default' marks the pool as holding
// the outgoing default (bucket 2); any other live row is another source's
// plan (bucket 3); no rows at all is a plan-less pool (bucket 1).
GetLivePlanAttachmentsWithSourceByPool(ctx context.Context, poolID string) ([]GetLivePlanAttachmentsWithSourceByPoolRow, error)
// Live (non-ended) provisions delivering a product. Tier add/remove aligns
// each of these to the product's new conferral shape.
GetLivePoolProvisionsByProductID(ctx context.Context, productID string) ([]PoolProvision, error)
// Live (non-ended) provisions of a subscription, one per product. Reconcile
// diffs these against the subscription's desired-by-product line items.
GetLivePoolProvisionsBySubscriptionID(ctx context.Context, subscriptionID uuid.NullUUID) ([]PoolProvision, error)
GetNumericEntitlementByPoolAndResource(ctx context.Context, arg GetNumericEntitlementByPoolAndResourceParams) (NumericEntitlement, error)
GetPoolProvisionByGrantID(ctx context.Context, grantID uuid.NullUUID) (PoolProvision, error)
GetPoolProvisionByProvisionID(ctx context.Context, provisionID string) (PoolProvision, error)
GetPoolProvisionBySubscriptionID(ctx context.Context, subscriptionID uuid.NullUUID) (PoolProvision, error)
// Writes to core.pool_provisions go through the conferral functions
// (queries/conferral.sql) alone; core_writer holds no direct DML on this
// table (migration 00005 enclosure). Only read paths live here.
GetPoolProvisionsByPoolID(ctx context.Context, poolID string) ([]PoolProvision, error)
GetPrimaryPoolAssignmentByWorkspace(ctx context.Context, workspaceID string) (PoolAssignment, error)
// Single-key lookup for the rule-authoring handler: rule_type is derived
// server-side from the key's kind, never taken from client input.
GetResourceKey(ctx context.Context, resourceKey string) (ResourceKey, error)
GetResourcePoolByID(ctx context.Context, poolID string) (ResourcePool, error)
GetResourcePoolsByOrgID(ctx context.Context, orgID string) ([]ResourcePool, error)
GetUsageByPoolAndResource(ctx context.Context, arg GetUsageByPoolAndResourceParams) (NumericEntitlementUsage, error)
// Update-only by design: a lapse never creates a row. Absence of a row means
// the key was never conferred; granted = FALSE means conferred, then lapsed.
LapseBooleanEntitlement(ctx context.Context, arg LapseBooleanEntitlementParams) (int64, error)
ListActiveEntitlementSets(ctx context.Context) ([]EntitlementSet, error)
ListAllGrants(ctx context.Context) ([]Grant, error)
ListBooleanEntitlementsByPoolID(ctx context.Context, poolID string) ([]BooleanEntitlement, error)
ListContributionsByEntitlementID(ctx context.Context, entitlementID string) ([]NumericEntitlementContribution, error)
// Returns only grants currently delivering entitlements to a pool in the
// given org — i.e. grants with at least one provision in status='active'.
// Used by the member-facing Sources panel where audit history would be
// noise (members only need to see what they actually have right now).
// DISTINCT collapses multi-provision grants to one row.
ListDeliveringGrantsByOrgID(ctx context.Context, grantedToOrgID uuid.NullUUID) ([]Grant, error)
ListEntitlementSets(ctx context.Context) ([]EntitlementSet, error)
ListGrantsByOrgID(ctx context.Context, grantedToOrgID uuid.NullUUID) ([]Grant, error)
// The one shared delivery-state derivation (ux-honest-surfaces design
// decision 1): every operator surface that lists grants renders from this
// query so the grants index and the org-detail composite can never
// disagree about what "live" / "superseded" / "inactive" mean.
//
// live -> at least one linked pool_provision is status='active'
// superseded -> not live, AND a later grant actually names this one as
// its extends_grant_id ancestor (a replacement was issued
// -- see replaced_by_grant_id below)
// inactive -> not live and not superseded: revoked/expired with no
// recorded successor, or a grant that never delivered
//
// This is deliberately narrower than "not live" alone: a grant whose
// provision simply ended (revoked, expired) with no replacement grant on
// record is "inactive", not "superseded" -- "superseded" is reserved for
// the case the UI can point at a specific replacing grant (the lineage
// requirement: a superseded row must be able to name what replaced it).
//
// replaced_by_grant_id is the most recently created grant (if any) whose
// extends_grant_id points at this row; NULL when nothing replaced it.
// extends_grant_id (this grant's own ancestor pointer) is passed through
// unchanged so the UI can walk lineage in either direction.
//
// Off-ladder grants (add-ons / usage / one-time) have no ladder attachment,
// so activated_at / ended_at may be NULL even when delivery_state='live'.
// Ordered live-first, then created_at DESC so the operationally-relevant
// row appears at the top with history beneath.
//
// sqlc.narg(org_id): NULL returns every grant system-wide (the grants
// index, /operator/grants); set, scopes to one organization (org-detail).
ListGrantsWithDelivery(ctx context.Context, orgID uuid.NullUUID) ([]ListGrantsWithDeliveryRow, error)
// Paginated, searchable, filterable system-wide variant of
// ListGrantsWithDelivery for /operator/grants (operator-list-scale,
// design D4). Same derivation, join shape, and ordering as
// ListGrantsWithDelivery above -- do not let the two drift, and never
// scope this one to an org_id; the org-detail composite keeps calling
// ListGrantsWithDelivery unpaged.
//
// sqlc.narg(q): NULL means search is inactive and every row matches.
// Non-NULL matches a grant when the granted-to organization's name
// ILIKE's the term, OR the grant's product_id is present in
// sqlc.narg(product_ids) -- the grants module cannot query the billing
// schema directly, so the caller (Go) pre-resolves product IDs whose name
// matches the search term and passes them here; a NULL or empty array
// with a non-NULL q simply means the q criterion rides on org name alone.
//
// sqlc.narg(delivery_state): NULL returns every delivery state; otherwise
// only rows whose derived state equals the value. The HAVING clause below
// repeats the exact CASE expression from the SELECT list (HAVING cannot
// reference a SELECT-list alias) so the filter can never disagree with
// what the SELECT list -- and therefore the Go derivation reading it --
// renders as that row's state (a mixed-fixture test pins this agreement).
//
// count(*) OVER() is evaluated after GROUP BY/HAVING, so with the GROUP
// BY below it counts grouped (one-per-grant) rows that passed WHERE and
// HAVING -- the true total of matching grants, not a join-multiplied
// count of the underlying pool_provisions/pool_provision_ladders rows.
ListGrantsWithDeliveryPage(ctx context.Context, arg ListGrantsWithDeliveryPageParams) ([]ListGrantsWithDeliveryPageRow, error)
// The whole population for the org-type default-change classification in one
// round trip: one row per (org, live plan attachment), plus a row with NULL
// pool for orgs lacking a default pool and a row with NULL attachment for
// plan-less pools (LEFT JOINs). Replaces a per-org query pair, which does not
// scale past a few hundred organizations of one type.
ListLivePlanPositionsByOrgType(ctx context.Context, orgType string) ([]ListLivePlanPositionsByOrgTypeRow, error)
// The tier-removal preview/commit population in one round trip: every live
// (active|suspended) junction on this ladder whose provision delivers this
// product, with the org (name/slug) and grant provenance so holders classify
// per position source (default-sourced needs a disposition; any other source
// is align-shrunk and never force-ended).
ListLiveTierHoldersByLadderProduct(ctx context.Context, arg ListLiveTierHoldersByLadderProductParams) ([]ListLiveTierHoldersByLadderProductRow, error)
ListNumericEntitlementUsageByPoolID(ctx context.Context, poolID string) ([]NumericEntitlementUsage, error)
ListNumericEntitlementsByPoolID(ctx context.Context, poolID string) ([]NumericEntitlement, error)
// Per-resource usage counters for a pool joined to their materialized
// limit (used vs limit per resource key), for the org-detail pools panel
// (ux-honest-surfaces: "pool status and usage are visible on the
// organization view"). A counter row exists only under a materialized
// numeric entitlement (invariant 9, resource-pools card), so the JOIN
// never orphans.
ListPoolUsageWithLimitsByPoolID(ctx context.Context, poolID string) ([]ListPoolUsageWithLimitsByPoolIDRow, error)
ListPoolsGrantedBooleanKey(ctx context.Context, resourceKey string) ([]ListPoolsGrantedBooleanKeyRow, error)
// Recent grants for the operator landing activity timeline. Returns the
// raw row data with org_id + granted_by_person_id; Go-side merger resolves
// those UUIDs to display names via batch lookups (avoids cross-schema
// joins that don't fit per-module sqlc scope). Only org-targeted grants —
// person-targeted and billing-account-targeted grants don't show up on
// the org-centric operator timeline.
ListRecentGrants(ctx context.Context, limit int32) ([]ListRecentGrantsRow, error)
// Recent transitions for the operator landing activity timeline. Joins to
// core.resource_pools to resolve the org_id (same schema, safe for
// sqlc). Operator-actor transitions carry actor_id; system/webhook actors
// don't, so person_id is nullable in the result.
ListRecentTransitions(ctx context.Context, limit int32) ([]ListRecentTransitionsRow, error)
// Display metadata for entitlement rendering: each key's human-friendly
// label plus its owning integration's display name. LEFT JOIN because
// provider NULL = platform-owned/pooled (see the resource_keys DDL
// comment); such keys render un-attributed.
ListResourceKeyLabels(ctx context.Context) ([]ListResourceKeyLabelsRow, error)
ListResourceKeys(ctx context.Context) ([]ResourceKey, error)
// Every pool row for the organization regardless of status -- unlike
// GetResourcePoolsByOrgID's active-only filter, this does not hide a
// suspended or archived pool from view. The org-detail composite uses
// this for its pools panel so an operator sees a pool's actual status
// (ux-honest-surfaces requirement: "pool status and usage are visible on
// the organization view") instead of the pool silently vanishing from the
// list, and so "this org has zero pool rows" (the pool-less breakage
// case) is distinguishable from "this org's only pool exists but is not
// active".
ListResourcePoolsByOrgIDAnyStatus(ctx context.Context, orgID string) ([]ResourcePool, error)
// Writes to core.pool_provision_transitions go through the conferral functions
// (queries/conferral.sql) alone; core_writer holds no direct DML on this
// table (migration 00005 enclosure). Only read paths live here.
ListTransitionsByPool(ctx context.Context, poolID string) ([]PoolProvisionTransition, error)
ListTransitionsByProvision(ctx context.Context, provisionID uuid.NullUUID) ([]PoolProvisionTransition, error)
RevokeGrant(ctx context.Context, arg RevokeGrantParams) (Grant, error)
UpdateEntitlementSet(ctx context.Context, arg UpdateEntitlementSetParams) (EntitlementSet, error)
UpdateEntitlementSetRule(ctx context.Context, arg UpdateEntitlementSetRuleParams) (EntitlementSetRule, error)
UpdateNumericEntitlementLimit(ctx context.Context, arg UpdateNumericEntitlementLimitParams) (NumericEntitlement, error)
UpsertBooleanEntitlementGranted(ctx context.Context, arg UpsertBooleanEntitlementGrantedParams) (BooleanEntitlement, error)
}
var _ Querier = (*Queries)(nil)