package store import ( "context" "encoding/json" ) func (m *Memory) GetRoleDataset(_ context.Context, tenantID string) (*RoleDataset, error) { m.mu.RLock() defer m.mu.RUnlock() revs := m.roleSets[tenantID] if len(revs) == 0 { return nil, ErrNotFound } cp := revs[len(revs)-1] return &cp, nil } func (m *Memory) SaveRoleDataset(_ context.Context, w RoleDatasetWrite) (*RoleDataset, bool, error) { if !json.Valid(w.Data) || w.CatalogueVersion == "" || w.By == "" { return nil, false, ErrInvalidInput } m.mu.Lock() defer m.mu.Unlock() if _, ok := m.tenants[w.TenantID]; !ok { return nil, false, ErrNotFound } revs := m.roleSets[w.TenantID] current := len(revs) if w.ExpectedRevision != current { return nil, false, &RevisionConflict{Current: current} } if current > 0 { cur := revs[current-1] if cur.CatalogueVersion == w.CatalogueVersion && sameJSON(cur.Data, w.Data) { return &cur, false, nil } } next := RoleDataset{ TenantID: w.TenantID, Data: append(json.RawMessage(nil), w.Data...), CatalogueVersion: w.CatalogueVersion, Revision: current + 1, UpdatedBy: w.By, UpdatedAt: w.At.UTC(), } m.roleSets[w.TenantID] = append(revs, next) cp := next return &cp, true, nil } func (m *Memory) GetRoleDatasetRevision(_ context.Context, tenantID string, revision int) (*RoleDataset, error) { m.mu.RLock() defer m.mu.RUnlock() revs := m.roleSets[tenantID] if revision < 1 || revision > len(revs) { return nil, ErrNotFound } cp := revs[revision-1] return &cp, nil }