memory

package
v0.12.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package memory is the in-process Repository driver. It backs both fast unit tests (no gRPC, no docker) and local-development runs where a full EntDB stack is overkill.

All operations are mutex-protected so tests using t.Parallel() are race-free. The driver keeps the same surface as the EntDB-backed driver — service.Repository plus a no-op service.DB — so the driver-selection helper in internal/repo/driver.go can hand it back from Build like any other backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repo

type Repo struct {
	// contains filtered or unexported fields
}

Repo is the in-memory implementation of service.Repository.

func New

func New() *Repo

New returns an empty Repo.

func (*Repo) AddOrganizationMember added in v0.7.1

func (r *Repo) AddOrganizationMember(_ context.Context, m *service.OrganizationMembership) (string, error)

func (*Repo) ConsumeEmailLoginCode added in v0.11.0

func (r *Repo) ConsumeEmailLoginCode(_ context.Context, email string, atMs int64) (*service.EmailLoginCodeRecord, error)

ConsumeEmailLoginCode atomically marks the email's unconsumed, unexpired code consumed and returns it. Any second caller, an expired code, or a missing code returns ErrEmailLoginCodeInvalid.

func (*Repo) ConsumeMagicLinkToken added in v0.11.0

func (r *Repo) ConsumeMagicLinkToken(_ context.Context, tokenHash string, atMs int64) (*service.MagicLinkTokenRecord, error)

ConsumeMagicLinkToken atomically marks an unconsumed, unexpired token consumed and returns it. A replay, an expired token, or a missing token returns ErrMagicLinkInvalid.

func (*Repo) ConsumeOAuthOneTimeCode added in v0.9.0

func (r *Repo) ConsumeOAuthOneTimeCode(_ context.Context, codeHash string, atMs int64) (*service.OAuthOneTimeCodeRecord, error)

ConsumeOAuthOneTimeCode atomically marks an unconsumed, unexpired code consumed and returns its record. The mutex held across read+check+write makes this CAS trivially correct for the in-process driver: any second caller (or an expired code) returns ErrOAuthCodeInvalid.

func (*Repo) ConsumeQrLoginSession added in v0.7.2

func (r *Repo) ConsumeQrLoginSession(_ context.Context, nodeID string, atMs int64) error

ConsumeQrLoginSession atomically transitions an approved session to consumed. The mutex held across read+check+write makes this CAS trivially correct for the in-process driver: any second caller sees status != "approved" and returns ErrQrLoginNotPending.

func (*Repo) ConsumeRefreshTokenByHash

func (r *Repo) ConsumeRefreshTokenByHash(_ context.Context, hash string, atMs int64) error

ConsumeRefreshTokenByHash atomically marks the row consumed. Returns service.ErrUnauthenticated if the row is missing or already consumed, so concurrent rotations resolve to exactly one winner.

func (*Repo) CountEmailChangeTokens added in v0.8.0

func (r *Repo) CountEmailChangeTokens() int

CountEmailChangeTokens is a test helper; see CountPasswordResetTokens.

func (*Repo) CountEmailVerificationTokens added in v0.8.0

func (r *Repo) CountEmailVerificationTokens() int

CountEmailVerificationTokens is a test helper; see CountPasswordResetTokens.

func (*Repo) CountLoginChallenges added in v0.8.0

func (r *Repo) CountLoginChallenges() int

CountLoginChallenges is a test helper; see CountPasswordResetTokens.

func (*Repo) CountPasskeyChallenges added in v0.8.0

func (r *Repo) CountPasskeyChallenges() int

CountPasskeyChallenges is a test helper; see CountPasswordResetTokens.

func (*Repo) CountPasswordResetTokens added in v0.8.0

func (r *Repo) CountPasswordResetTokens() int

CountPasswordResetTokens is a test helper used by the sweeper regression to infer "rows deleted" from "rows still present" after the v1.14.0 contract dropped the row-count return.

func (*Repo) CountRefreshTokensForUser

func (r *Repo) CountRefreshTokensForUser(userID string) int

CountRefreshTokensForUser is a test helper for assertions about session count.

func (*Repo) CreateEmailChangeToken

func (r *Repo) CreateEmailChangeToken(_ context.Context, t *service.EmailChangeToken) error

func (*Repo) CreateEmailVerificationToken

func (r *Repo) CreateEmailVerificationToken(_ context.Context, t *service.EmailVerificationToken) error

func (*Repo) CreateIdentityVerification added in v0.4.0

func (r *Repo) CreateIdentityVerification(_ context.Context, rec *service.IdentityVerificationRecord) error

func (*Repo) CreateLoginChallenge

func (r *Repo) CreateLoginChallenge(_ context.Context, rec *service.LoginChallengeRecord) (string, error)

func (*Repo) CreateMagicLinkToken added in v0.11.0

func (r *Repo) CreateMagicLinkToken(_ context.Context, rec *service.MagicLinkTokenRecord) (string, error)

func (*Repo) CreateOAuthIdentity

func (r *Repo) CreateOAuthIdentity(_ context.Context, oi *service.OAuthIdentity) error

func (*Repo) CreateOAuthOneTimeCode added in v0.9.0

func (r *Repo) CreateOAuthOneTimeCode(_ context.Context, rec *service.OAuthOneTimeCodeRecord) (string, error)

func (*Repo) CreateOrganization added in v0.7.1

func (r *Repo) CreateOrganization(_ context.Context, o *service.Organization) (string, error)

func (*Repo) CreatePasskeyChallenge

func (r *Repo) CreatePasskeyChallenge(_ context.Context, rec *service.PasskeyChallengeRecord) (string, error)

func (*Repo) CreatePasskeyCredential

func (r *Repo) CreatePasskeyCredential(_ context.Context, rec *service.PasskeyCredRecord) (string, error)

func (*Repo) CreatePasswordResetToken

func (r *Repo) CreatePasswordResetToken(_ context.Context, t *service.PasswordResetToken) error

func (*Repo) CreateQrLoginSession

func (r *Repo) CreateQrLoginSession(_ context.Context, rec *service.QrLoginSessionRecord) (string, error)

func (*Repo) CreateRecoveryCode

func (r *Repo) CreateRecoveryCode(_ context.Context, rec *service.RecoveryCodeRecord) (string, error)

func (*Repo) CreateRefreshToken

func (r *Repo) CreateRefreshToken(_ context.Context, rec *service.RefreshTokenRecord) (string, error)

func (*Repo) CreateSession added in v0.8.0

func (r *Repo) CreateSession(_ context.Context, s *service.SessionRecord) (string, error)

func (*Repo) CreateTotpCredential

func (r *Repo) CreateTotpCredential(_ context.Context, rec *service.TotpCredRecord) (string, error)

func (*Repo) CreateUser

func (r *Repo) CreateUser(_ context.Context, u *service.User) (string, error)

func (*Repo) DeleteExpiredEmailChangeTokens added in v0.7.1

func (r *Repo) DeleteExpiredEmailChangeTokens(_ context.Context, beforeMs int64, limit int) error

func (*Repo) DeleteExpiredEmailLoginCodes added in v0.11.0

func (r *Repo) DeleteExpiredEmailLoginCodes(_ context.Context, beforeMs int64, limit int) error

func (*Repo) DeleteExpiredEmailVerificationTokens added in v0.7.1

func (r *Repo) DeleteExpiredEmailVerificationTokens(_ context.Context, beforeMs int64, limit int) error

func (*Repo) DeleteExpiredLoginChallenges added in v0.7.1

func (r *Repo) DeleteExpiredLoginChallenges(_ context.Context, beforeMs int64, limit int) error

func (*Repo) DeleteExpiredMagicLinkTokens added in v0.11.0

func (r *Repo) DeleteExpiredMagicLinkTokens(_ context.Context, beforeMs int64, limit int) error

func (*Repo) DeleteExpiredOAuthOneTimeCodes added in v0.9.0

func (r *Repo) DeleteExpiredOAuthOneTimeCodes(_ context.Context, beforeMs int64, limit int) error

func (*Repo) DeleteExpiredPasswordResetTokens added in v0.7.1

func (r *Repo) DeleteExpiredPasswordResetTokens(_ context.Context, beforeMs int64, limit int) error

func (*Repo) DeleteExpiredWebAuthnChallenges added in v0.7.1

func (r *Repo) DeleteExpiredWebAuthnChallenges(_ context.Context, beforeMs int64, limit int) error

func (*Repo) DeleteLoginChallenge

func (r *Repo) DeleteLoginChallenge(_ context.Context, nodeID string) error

func (*Repo) DeletePasskeyChallenge

func (r *Repo) DeletePasskeyChallenge(_ context.Context, nodeID string) error

func (*Repo) DeleteRecoveryCodesForUser

func (r *Repo) DeleteRecoveryCodesForUser(_ context.Context, userID string) error

func (*Repo) DeleteRefreshToken

func (r *Repo) DeleteRefreshToken(_ context.Context, nodeID string) error

func (*Repo) DeleteRefreshTokensForUser

func (r *Repo) DeleteRefreshTokensForUser(_ context.Context, userID string) error

func (*Repo) DeleteTotpCredential

func (r *Repo) DeleteTotpCredential(_ context.Context, nodeID string) error

func (*Repo) DeleteTotpCredentialsForUser

func (r *Repo) DeleteTotpCredentialsForUser(_ context.Context, userID string) error

func (*Repo) ExecuteAtomic

func (r *Repo) ExecuteAtomic(context.Context, string, string, []sdk.Operation) (*sdk.CommitResult, error)

func (*Repo) FindEmailChangeTokenByHash

func (r *Repo) FindEmailChangeTokenByHash(_ context.Context, hash string) (*service.EmailChangeToken, error)

func (*Repo) FindEmailLoginCodeByEmail added in v0.11.0

func (r *Repo) FindEmailLoginCodeByEmail(_ context.Context, email string) (*service.EmailLoginCodeRecord, error)

func (*Repo) FindEmailVerificationTokenByHash

func (r *Repo) FindEmailVerificationTokenByHash(_ context.Context, hash string) (*service.EmailVerificationToken, error)

func (*Repo) FindInvitationByHash

func (r *Repo) FindInvitationByHash(_ context.Context, tokenHash string) (*service.InvitationRecord, error)

func (*Repo) FindPasswordResetTokenByHash

func (r *Repo) FindPasswordResetTokenByHash(_ context.Context, hash string) (*service.PasswordResetToken, error)

func (*Repo) FindQrLoginSession

func (r *Repo) FindQrLoginSession(_ context.Context, sessionID string) (*service.QrLoginSessionRecord, error)

func (*Repo) FindRecoveryCodeByHash

func (r *Repo) FindRecoveryCodeByHash(_ context.Context, userID, hash string) (*service.RecoveryCodeRecord, error)

func (*Repo) FindRefreshTokenByHash

func (r *Repo) FindRefreshTokenByHash(_ context.Context, hash string) (*service.RefreshTokenRecord, error)

func (*Repo) FindRefreshTokenByHashIncludingConsumed

func (r *Repo) FindRefreshTokenByHashIncludingConsumed(_ context.Context, hash string) (*service.RefreshTokenRecord, error)

func (*Repo) FindUserByEmail

func (r *Repo) FindUserByEmail(_ context.Context, email string) (*service.User, error)

func (*Repo) FindUserByProviderID

func (r *Repo) FindUserByProviderID(_ context.Context, provider, providerUserID string) (*service.User, error)

func (*Repo) GetEdgesFrom

func (r *Repo) GetEdgesFrom(context.Context, string, string, string, int) ([]*sdk.Edge, error)

func (*Repo) GetEdgesTo

func (r *Repo) GetEdgesTo(context.Context, string, string, string, int) ([]*sdk.Edge, error)

func (*Repo) GetIdentityVerification added in v0.4.0

func (r *Repo) GetIdentityVerification(_ context.Context, verificationID string) (*service.IdentityVerificationRecord, error)

func (*Repo) GetLatestIdentityVerificationForUser added in v0.4.0

func (r *Repo) GetLatestIdentityVerificationForUser(_ context.Context, userID string) (*service.IdentityVerificationRecord, error)

func (*Repo) GetLoginChallengeByChallengeID

func (r *Repo) GetLoginChallengeByChallengeID(_ context.Context, challengeID string) (*service.LoginChallengeRecord, error)

func (*Repo) GetNode

func (r *Repo) GetNode(context.Context, string, string, int, string) (*sdk.Node, error)

func (*Repo) GetOrganization added in v0.7.1

func (r *Repo) GetOrganization(_ context.Context, orgID string) (*service.Organization, error)

func (*Repo) GetOrganizationBySlug added in v0.7.1

func (r *Repo) GetOrganizationBySlug(_ context.Context, slug string) (*service.Organization, error)

func (*Repo) GetPasskeyChallenge

func (r *Repo) GetPasskeyChallenge(_ context.Context, nodeID string) (*service.PasskeyChallengeRecord, error)

func (*Repo) GetPasskeyCredentialByCredID

func (r *Repo) GetPasskeyCredentialByCredID(_ context.Context, credentialID string) (*service.PasskeyCredRecord, error)

func (*Repo) GetSessionBySid added in v0.8.0

func (r *Repo) GetSessionBySid(_ context.Context, sid string) (*service.SessionRecord, error)

func (*Repo) GetTotpCredential

func (r *Repo) GetTotpCredential(_ context.Context, userID string) (*service.TotpCredRecord, error)

func (*Repo) GetUser

func (r *Repo) GetUser(_ context.Context, userID string) (*service.User, error)

func (*Repo) IncrementEmailLoginCodeAttempts added in v0.11.0

func (r *Repo) IncrementEmailLoginCodeAttempts(_ context.Context, nodeID string) error

func (*Repo) IncrementFailedLoginCount

func (r *Repo) IncrementFailedLoginCount(_ context.Context, userID string) (int32, error)

func (*Repo) ListOAuthIdentitiesForUser

func (r *Repo) ListOAuthIdentitiesForUser(_ context.Context, userID string) ([]*service.OAuthIdentity, error)

func (*Repo) ListOrganizationsForUser added in v0.7.1

func (r *Repo) ListOrganizationsForUser(_ context.Context, userID string) ([]*service.Organization, error)

func (*Repo) ListPasskeyCredentials

func (r *Repo) ListPasskeyCredentials(_ context.Context, userID string) ([]*service.PasskeyCredRecord, error)

func (*Repo) MarkEmailChangeTokenConsumed

func (r *Repo) MarkEmailChangeTokenConsumed(_ context.Context, id string, atMs int64) error

func (*Repo) MarkEmailVerificationTokenConsumed

func (r *Repo) MarkEmailVerificationTokenConsumed(_ context.Context, id string, atMs int64) error

func (*Repo) MarkPasswordResetTokenConsumed

func (r *Repo) MarkPasswordResetTokenConsumed(_ context.Context, id string, atMs int64) error

func (*Repo) QueryNodes

func (r *Repo) QueryNodes(context.Context, string, string, int, map[string]any) ([]*sdk.Node, error)

func (*Repo) RegisterUserInTenant added in v0.7.1

func (r *Repo) RegisterUserInTenant(_ context.Context, _, _, _, _, _ string) error

RegisterUserInTenant is a no-op on the in-memory driver. The in-memory store bypasses the EntDB two-tier model entirely, so there is no global registry / tenant-membership to enforce.

func (*Repo) ResetFailedLoginCount

func (r *Repo) ResetFailedLoginCount(_ context.Context, userID string) error

func (*Repo) RevokeSession added in v0.8.0

func (r *Repo) RevokeSession(_ context.Context, sid string, atMs int64) error

RevokeSession is idempotent: a no-op if the session does not exist or is already revoked. Concurrent revoke calls converge on the same final state rather than racing each other into failure.

func (*Repo) RevokeSessionsForUser added in v0.8.0

func (r *Repo) RevokeSessionsForUser(_ context.Context, userID string, atMs int64) error

RevokeSessionsForUser revokes every active session for the user. Existing revoked rows are left alone so the original revoke timestamp survives.

func (*Repo) SearchNodes

func (r *Repo) SearchNodes(context.Context, string, string, int, string) ([]*sdk.Node, error)

func (*Repo) SetUserEmailVerified

func (r *Repo) SetUserEmailVerified(_ context.Context, userID string, atMs int64) error

func (*Repo) SetUserIDVVerified added in v0.4.2

func (r *Repo) SetUserIDVVerified(_ context.Context, userID string, atMs int64) error

func (*Repo) SetUserLockedUntil

func (r *Repo) SetUserLockedUntil(_ context.Context, userID string, lockedUntilMs int64) error

func (*Repo) UpdateIdentityVerificationStatus added in v0.4.0

func (r *Repo) UpdateIdentityVerificationStatus(_ context.Context, verificationID, status, rejectionReason string, completedAtMs, updatedAtMs int64) error

func (*Repo) UpdateInvitation

func (r *Repo) UpdateInvitation(_ context.Context, nodeID string, fields map[string]any) error

func (*Repo) UpdatePasskeyCredential

func (r *Repo) UpdatePasskeyCredential(_ context.Context, nodeID string, fields map[string]any) error

func (*Repo) UpdateQrLoginSession

func (r *Repo) UpdateQrLoginSession(_ context.Context, nodeID string, fields map[string]any) error

func (*Repo) UpdateRecoveryCode

func (r *Repo) UpdateRecoveryCode(_ context.Context, nodeID string, fields map[string]any) error

func (*Repo) UpdateTotpCredential

func (r *Repo) UpdateTotpCredential(_ context.Context, nodeID string, fields map[string]any) error

func (*Repo) UpdateUser

func (r *Repo) UpdateUser(_ context.Context, userID string, fields map[string]any) error

func (*Repo) UpdateUserEmail

func (r *Repo) UpdateUserEmail(_ context.Context, userID, newEmail string, atMs int64) error

func (*Repo) UpsertEmailLoginCode added in v0.11.0

func (r *Repo) UpsertEmailLoginCode(_ context.Context, rec *service.EmailLoginCodeRecord) (string, error)

UpsertEmailLoginCode replaces any existing code for the email so at most one is live per address. Keyed by email (the unique field).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL