package storecontract import ( "time" ) // Resource is one control-plane resource document: the stored value for an // org's kind, its revision, and the audit record written with the last write. // Resource and ResourceWrite live here so the UI-side consumers can reference // them without linking the PostgreSQL implementation. type Resource struct { OrgID string Kind string Value []byte Version int64 Actor string Source string RequestID string ExpectedVersion int64 CurrentVersion int64 At time.Time } // DefaultOrgID is the org every resource written before orgs existed belongs // to, and the org a request that names none acts in. const DefaultOrgID = "org-sys" // ResourceAuditKey is the sys_audit record key of one org's resource kind. The // default org keeps the bare kind, so audit rows written before resources were // per-org still resolve. func ResourceAuditKey(orgID, kind string) string { if orgID == DefaultOrgID { return kind } return orgID + "/" + kind } // ResourceWrite is a control-plane resource write request. ExpectedVersion is // the optimistic-concurrency guard: a write whose expectation does not match // the stored revision is refused with ErrResourceVersionConflict. type ResourceWrite struct { OrgID string Kind string Value []byte Actor string Source string RequestID string ExpectedVersion int64 At time.Time }