models4datatug

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package models4datatug holds this extension's database objects and the DALgo keys they are stored under. Shared linkage reuses published contract DTOs; no database client or peer extension implementation is imported.

Copyright 2026 Sneat.co

Index

Constants

View Source
const (
	FreeMoneySettingsCollection = "datatugFreeMoneySettings"
	FreeMoneyMonthCollection    = "datatugFreeMoneyMonths"
)
View Source
const (
	GithubAppCredentialsCollection = "datatug_github_app_credentials"
	GithubOAuthStatesCollection    = "datatug_github_oauth_states"
)
View Source
const (
	GitHubProjectInitializing = "initializing"
	GitHubProjectReady        = "ready"
)
View Source
const (
	SpacesCollection  = "spaces"
	PlanCollection    = "plan"
	AIUsageCollection = "aiUsage"
)
View Source
const (
	PlanApplicationCollection = "datatugPlanApplications"
	PaidMoneyMonthCollection  = "datatugPaidMoneyMonths"
)
View Source
const (
	// ProjectsCollection stores DataTug projects.
	ProjectsCollection = "datatug_projects"

	// UsersCollection is the platform's users collection.
	UsersCollection = "users"

	// UserExtCollection is the platform's collection of per-extension user
	// documents: users/{userID}/ext/{extID}. The DataTug extension's user data
	// (which stores and projects the user can see) lives there, never inline in
	// the core users/{userID} document. This mirrors the key that
	// sneat-core-modules' dal4userus.NewUserExtKey builds; the module builds it
	// itself so that it depends on dal-go only.
	UserExtCollection = "ext"

	// FirestoreStoreID is the store id of the DataTug cloud store. It is what
	// the web client sends as `?store=` and the key of the store brief in the
	// user's index.
	FirestoreStoreID = "firestore"

	// FirestoreStoreTitle is the human-readable title of the cloud store.
	FirestoreStoreTitle = "DataTug cloud"

	// GithubStoreID is the store id of a project hosted in a GitHub repository —
	// the id the web client's GitHub reader and navigation use.
	GithubStoreID = "github.com"

	// GithubStoreType is the store type reported for GitHub-hosted projects.
	GithubStoreType = "github"

	// GithubStoreTitle is the human-readable title of the GitHub store.
	GithubStoreTitle = "GitHub"

	// DefaultGithubProjectFolder is the repo folder a project lives in when the
	// user does not name one — the same default the web client's
	// parseGithubProjectId() applies.
	DefaultGithubProjectFolder = "datatug"

	// AccessPrivate means only the userIDs listed on the project can read it.
	AccessPrivate = "private"
)
View Source
const (
	ProjectRoleViewer      ProjectRoleID = "viewer"
	ProjectRoleContributor ProjectRoleID = "contributor"
	ProjectRoleOwner       ProjectRoleID = "owner"

	ProjectRoleCatalogVersion uint16 = 1
)
View Source
const (
	QueryActivitySourceID                = "datatug-browser-activity/1"
	QueryActivityContextsCollection      = "queryActivityContexts"
	QueryActivityContextQuotasCollection = "queryActivityContextQuotas"
	QueryActivityReceiptsCollection      = "queryActivityReceipts"
	QueryActivityPendingCollection       = "queryActivityPending"
	QueryActivityMaxContextsPerMinute    = 60
	QueryActivityMaxReportsPerMinute     = 60
)
View Source
const (
	QueryActivityPendingStatePending   = "pending"
	QueryActivityPendingStateDelivered = "delivered"
)
View Source
const (
	QueryActivityPeriodCheckpointsCollection = "queryActivityPeriodCheckpoints"
	QueryActivityPeriodSequencesCollection   = "queryActivityPeriodSequences"
	QueryActivityCheckpointOpening           = "opening"
	QueryActivityCheckpointReady             = "ready"
	QueryActivityCheckpointClosing           = "closing"
	QueryActivityCheckpointClosed            = "closed"
	QueryActivitySequencePending             = "pending"
	QueryActivitySequenceDelivered           = "delivered"
)
View Source
const (
	SharedProjectQueriesCollection       = "queries"
	SharedProjectQueryReceiptsCollection = "querySaveReceipts"
	MaxSharedProjectQueryBytes           = 512 << 10
)
View Source
const AccessProtected = "protected"
View Source
const GitHubQueryEditSourceID = "github-query-draft/1"
View Source
const ProjectAdmissionCollection = "projectAdmissions"
View Source
const ProtectedProjectQuotaCollection = "protectedProjectQuota"

These server-only roots require Firebase read/list exclusions at every depth before activation: spaces/{payer}/ext/datatug/protectedProjectQuota/{scope} and spaces/{projectSpace}/ext/datatug/projectAdmissions/{projectID}.

View Source
const QueryEditCandidateCollection = "queryEditCandidates"
View Source
const QueryEditUnclassified = "unclassified"

Variables

View Source
var ErrInvalidBusinessUsageWorkerState = errors.New("invalid business usage worker state")
View Source
var ErrInvalidFreeMoneyKey = errors.New("invalid Free money key scope")
View Source
var (
	ErrInvalidGitHubBinding = errors.New("invalid GitHub project binding")
)
View Source
var ErrInvalidGitHubQueryOperation = errors.New("invalid GitHub query operation")
View Source
var ErrInvalidQueryActivity = errors.New("invalid query activity record")
View Source
var ErrInvalidQueryActivityPeriod = errors.New("invalid query activity period checkpoint")
View Source
var ErrInvalidQueryEditCandidate = errors.New("invalid query edit candidate")

Functions

func CanonicalQueryActivityTime added in v0.20.0

func CanonicalQueryActivityTime(value time.Time) time.Time

CanonicalQueryActivityTime truncates to Firestore's durable microsecond timestamp precision. Callers must check raw server time against raw paid boundaries before using this value for any persisted time or digest.

func GitHubSharedProjectCreateDigest added in v0.14.0

func GitHubSharedProjectCreateDigest(actorID, spaceID, commandID, title, payer, mode, product string, source GitHubCreateSource) string

func NewAIUsageKey added in v0.4.0

func NewAIUsageKey(accountID, periodID string) *record.Key

func NewCurrentPlanKey added in v0.4.0

func NewCurrentPlanKey(accountID string) *record.Key

NewCurrentPlanKey names only the live entitlement document. Test-mode reconciliation deliberately uses a different key and never feeds readers.

func NewFreeMoneyGlobalMonthKey added in v0.8.0

func NewFreeMoneyGlobalMonthKey(mode, product, periodID string) (*record.Key, error)

NewFreeMoneyGlobalMonthKey selects the shared private UTC-month counter.

func NewFreeMoneyPersonMonthKey added in v0.8.0

func NewFreeMoneyPersonMonthKey(mode, product, verifiedUserID, periodID string) (*record.Key, error)

NewFreeMoneyPersonMonthKey selects a verified person's private UTC-month counter. The caller must supply a server-verified user ID.

func NewFreeMoneySettingsKey added in v0.8.0

func NewFreeMoneySettingsKey(mode, product string) (*record.Key, error)

NewFreeMoneySettingsKey selects one private configuration per mode and product. The caller must supply a server-resolved mode; no settings record is created here.

func NewGithubAppCredentialKey added in v0.13.0

func NewGithubAppCredentialKey(userID string) *record.Key

NewGithubAppCredentialKey addresses a private root-collection record for one Firebase user. It deliberately lives outside users/{uid}, whose recursive client-read rule would otherwise expose even encrypted credential metadata.

func NewGithubOAuthStateKey added in v0.13.0

func NewGithubOAuthStateKey(userID, stateDigest string) *record.Key

NewGithubOAuthStateKey addresses a single-use state in the private root collection. The id contains hashes of both the Firebase UID and OAuth state.

func NewGithubProjectID added in v0.2.0

func NewGithubProjectID(org, repo, folder string) string

NewGithubProjectID builds the id a GitHub-hosted project is addressed by: `repo@org@folder` — the format the web client's parseGithubProjectId() expects.

func NewPaidMoneyMonthKey added in v0.5.0

func NewPaidMoneyMonthKey(mode, family, accountID, periodID string) *record.Key

func NewPlanApplicationKey added in v0.5.0

func NewPlanApplicationKey(mode, family, accountID string) *record.Key

func NewProjectContactLinkageRecord added in v0.12.0

NewProjectContactLinkageRecord projects only the existing Contactus linkage fields. Mutation callers update those fields only, never contact identity or status. Contact authorization is supplied by the current-contact port.

func NewProjectKey

func NewProjectKey(projectID string) *record.Key

NewProjectKey builds the dalgo key of a project record.

func NewQueryActivityContextID added in v0.20.0

func NewQueryActivityContextID(actorID, projectID string, period contract4paymentus.UsagePeriodRef) string

NewQueryActivityContextID reuses one context per actor/project/paid period. Proof revisions update the current authority snapshot in place; they do not create rows or change the immutable operation identity.

func NewQueryActivityContextQuotaID added in v0.20.0

func NewQueryActivityContextQuotaID(actorID string, period contract4paymentus.UsagePeriodRef) string

func NewQueryActivityEventID added in v0.20.0

func NewQueryActivityEventID(contextID, operationID string) string

func NewQueryActivityPeriodID added in v0.23.1

func NewQueryActivityPeriodID(period contract4paymentus.UsagePeriodRef) string

func NewQueryActivityReceiptID added in v0.20.0

func NewQueryActivityReceiptID(actorID string, period contract4paymentus.UsagePeriodRef) string

func NewQueryEditCandidateID added in v0.18.0

func NewQueryEditCandidateID(actorID, operationID string) string

func NewTestPlanKey added in v0.4.0

func NewTestPlanKey(accountID string) *record.Key

func NewUserExtKey

func NewUserExtKey(userID, extID string) *record.Key

NewUserExtKey builds the dalgo key of a user's DataTug index record: users/{userID}/ext/{extID}.

func PaidSharedProjectCreateDigest added in v0.11.0

func PaidSharedProjectCreateDigest(actorID, spaceID, commandID, title, payer, mode, product string) string

func QueryActivityBindingDigest added in v0.20.0

func QueryActivityBindingDigest(actorID, spaceID, projectID string, period contract4paymentus.UsagePeriodRef, startUTC, endUTC, paidUntilUTC time.Time, payerBindingDigest, paidProofID, queryUseProofID string) string

QueryActivityBindingDigest freezes the canonical paid and query-use binding that authorized the first accepted report. It deliberately excludes later mutable authority revisions while retaining the original period fence.

func QueryActivityStructuralDigest added in v0.20.0

func QueryActivityStructuralDigest(r QueryActivityReceipt) string

func SharedProjectCreateDigest added in v0.10.0

func SharedProjectCreateDigest(actorID, spaceID, commandID, title string) string

SharedProjectCreateDigest freezes every command payload field; JSON provides unambiguous boundaries even if a caller tries separator-shaped values.

func SharedProjectQueryRequestDigest added in v0.27.0

func SharedProjectQueryRequestDigest(spaceID string, request dto.SaveQueryRequest) (string, error)

func SharedProjectQueryRevision added in v0.27.0

func SharedProjectQueryRevision(query datatug.QueryDefWithFolderPath) string

SharedProjectQueryRevision returns a content-derived opaque revision for the exact Core query DTO persisted by the Firestore adapter.

func ValidateProjectContactRef added in v0.12.0

func ValidateProjectContactRef(ref contract4linkage.RelationshipEntityRef) error

func ValidateSharedProjectIdentifier added in v0.10.0

func ValidateSharedProjectIdentifier(id string) error

ValidateSharedProjectIdentifier accepts one bounded path segment. Core Space authority separately validates that a Space exists and is eligible.

func ValidateSharedProjectTitle added in v0.10.0

func ValidateSharedProjectTitle(title string) error

Types

type AIUsageRecord added in v0.4.0

type AIUsageRecord struct {
	V         int              `json:"v" firestore:"v"`
	PeriodID  string           `json:"periodId" firestore:"periodId"`
	Used      int64            `json:"used" firestore:"used"`
	Questions int64            `json:"questions" firestore:"questions"`
	ByMember  map[string]int64 `json:"byMember,omitempty" firestore:"byMember,omitempty"`
	Capped    bool             `json:"capped,omitempty" firestore:"capped,omitempty"`
	ResetsAt  *time.Time       `json:"resetsAt,omitempty" firestore:"resetsAt,omitempty"`
	UpdatedAt *time.Time       `json:"updatedAt,omitempty" firestore:"updatedAt,omitempty"`
}

AIUsageRecord is the version-1 UTC-month usage document.

type BusinessUsageWorkerState added in v0.23.2

type BusinessUsageWorkerState struct {
	Version             int                     `firestore:"v"`
	Mode                contract4paymentus.Mode `firestore:"mode"`
	CheckpointAfterPath string                  `firestore:"checkpointAfterPath,omitempty"`
	PendingAfterPath    string                  `firestore:"pendingAfterPath,omitempty"`
	UpdatedAtUTC        time.Time               `firestore:"updatedAtUTC"`
}

BusinessUsageWorkerState stores only resumable collection-group scan positions. Business authority remains in each Space-scoped checkpoint.

func NewBusinessUsageWorkerStateRecord added in v0.23.2

func NewBusinessUsageWorkerStateRecord(mode contract4paymentus.Mode) (record.Record, *BusinessUsageWorkerState)

func (BusinessUsageWorkerState) Validate added in v0.23.2

func (s BusinessUsageWorkerState) Validate() error

type Created

type Created struct {
	At time.Time `json:"at" firestore:"at"`
}

Created holds the creation timestamp of a DataTug record.

type GitHubCreateSource added in v0.14.0

type GitHubCreateSource struct {
	Binding        GitHubProjectBinding `json:"binding" firestore:"binding"`
	ExpectedHead   string               `json:"expectedHead" firestore:"expectedHead"`
	TemplateID     string               `json:"templateID" firestore:"templateID"`
	TemplateCommit string               `json:"templateCommit" firestore:"templateCommit"`
}

GitHubCreateSource fixes the selected repository, branch head and pinned template in the admission receipt. Provider credentials are never included.

type GitHubProjectBinding added in v0.14.0

type GitHubProjectBinding struct {
	RepositoryID int64  `json:"repositoryID" firestore:"repositoryID"`
	Owner        string `json:"owner" firestore:"owner"`
	Name         string `json:"name" firestore:"name"`
	Folder       string `json:"folder" firestore:"folder"`
	Branch       string `json:"branch" firestore:"branch"`
}

GitHubProjectBinding is the immutable repository identity and project path. Owner/name are checked against GitHub on every request; they are never authority by themselves. Branch is the initially selected working branch.

func (GitHubProjectBinding) Validate added in v0.14.0

func (b GitHubProjectBinding) Validate() error

type GitHubProjectCreateOperation added in v0.14.0

type GitHubProjectCreateOperation struct {
	Version        int                  `firestore:"v"`
	ActorID        string               `firestore:"actorID"`
	OperationID    string               `firestore:"operationID"`
	SpaceID        string               `firestore:"spaceID"`
	ProjectID      string               `firestore:"projectID"`
	RequestDigest  string               `firestore:"requestDigest"`
	Binding        GitHubProjectBinding `firestore:"binding"`
	ExpectedHead   string               `firestore:"expectedHead"`
	CommittedHead  string               `firestore:"committedHead,omitempty"`
	TemplateID     string               `firestore:"templateID"`
	TemplateCommit string               `firestore:"templateCommit"`
	Status         string               `firestore:"status"`
	CreatedAt      time.Time            `firestore:"createdAt"`
}

GitHubProjectCreateOperation is server-only saga evidence. It binds a client operation ID to one actor, Space, payload and expected Git head before the provider write. A committed-but-not-finalized result can be reconciled; an uncertain outcome never releases quota or starts another commit blindly.

func NewGitHubProjectCreateOperationRecord added in v0.14.0

func NewGitHubProjectCreateOperationRecord(actorID, operationID string) (record.Record, *GitHubProjectCreateOperation)

The operation key is actor-wide, rather than Space/project scoped. Reusing one ID for a different Space, repository, branch or payload is detectable.

func (GitHubProjectCreateOperation) Match added in v0.14.0

func (o GitHubProjectCreateOperation) Match(actorID, operationID, spaceID, digest string) error

func (GitHubProjectCreateOperation) Validate added in v0.14.0

func (o GitHubProjectCreateOperation) Validate() error

type GitHubProjectLocator added in v0.14.0

type GitHubProjectLocator struct {
	Version      int       `firestore:"v"`
	RepositoryID int64     `firestore:"repositoryID"`
	Folder       string    `firestore:"folder"`
	SpaceID      string    `firestore:"spaceID"`
	ProjectID    string    `firestore:"projectID"`
	Status       string    `firestore:"status"`
	CreatedAt    time.Time `firestore:"createdAt"`
}

GitHubProjectLocator is a private uniqueness pointer, not a grant or a project. Its key is derived from immutable repository ID plus folder, so a repository rename cannot create a second shared project in another Space. The referenced shared project and its admission remain Space bounded.

func NewGitHubProjectLocatorRecord added in v0.14.0

func NewGitHubProjectLocatorRecord(repositoryID int64, folder string) (record.Record, *GitHubProjectLocator)

func (GitHubProjectLocator) Validate added in v0.14.0

func (l GitHubProjectLocator) Validate() error

type GitHubQueryOperation added in v0.14.0

type GitHubQueryOperation struct {
	Version       int                   `firestore:"v"`
	ActorID       string                `firestore:"actorID"`
	OperationID   string                `firestore:"operationID"`
	RequestDigest string                `firestore:"requestDigest"`
	SpaceID       string                `firestore:"spaceID,omitempty"`
	ProjectID     string                `firestore:"projectID,omitempty"`
	BodyChanged   bool                  `firestore:"bodyChanged,omitempty"`
	RepositoryID  int64                 `firestore:"repositoryID"`
	Folder        string                `firestore:"folder"`
	Branch        string                `firestore:"branch"`
	ExpectedHead  string                `firestore:"expectedHead"`
	QueryPath     string                `firestore:"queryPath"`
	CommittedHead string                `firestore:"committedHead,omitempty"`
	Result        dto.SaveQueryResponse `firestore:"result"`
	CreatedAt     time.Time             `firestore:"createdAt"`
}

GitHubQueryOperation records a server-only, actor-wide intent before any provider write. A retry can prove its exact commit and recover its result.

func NewGitHubQueryOperationRecord added in v0.14.0

func NewGitHubQueryOperationRecord(actorID, operationID string) (record.Record, *GitHubQueryOperation)

func (GitHubQueryOperation) Validate added in v0.14.0

func (o GitHubQueryOperation) Validate() error

type PaidMoneyMonth added in v0.5.0

type PaidMoneyMonth struct {
	V                   int    `json:"v" firestore:"v"`
	Mode                string `json:"mode" firestore:"mode"`
	AccountID           string `json:"accountId" firestore:"accountId"`
	PeriodID            string `json:"periodId" firestore:"periodId"`
	BasisRevision       int64  `json:"basisRevision" firestore:"basisRevision"`
	BasisMicroEUR       int64  `json:"basisMicroEUR" firestore:"basisMicroEUR"`
	SettledMicroEUR     int64  `json:"settledMicroEUR" firestore:"settledMicroEUR"`
	OutstandingMicroEUR int64  `json:"outstandingMicroEUR" firestore:"outstandingMicroEUR"`
	Frozen              bool   `json:"frozen" firestore:"frozen"`
}

PaidMoneyMonth matches the core paid-month fields. Core's published allocator/admission release must verify this shape before host binding.

type PlanApplication added in v0.5.0

type PlanApplication struct {
	V                             int      `json:"v" firestore:"v"`
	Mode                          string   `json:"mode" firestore:"mode"`
	Family                        string   `json:"family" firestore:"family"`
	AccountID                     string   `json:"accountId" firestore:"accountId"`
	OwnerSubscriptionID           string   `json:"ownerSubscriptionId" firestore:"ownerSubscriptionId"`
	OwnerGeneration               int64    `json:"ownerGeneration" firestore:"ownerGeneration"`
	SubscriptionRevision          int64    `json:"subscriptionRevision" firestore:"subscriptionRevision"`
	EffectDigest                  string   `json:"effectDigest" firestore:"effectDigest"`
	BasisVersion                  int64    `json:"basisVersion" firestore:"basisVersion"`
	BasisPeriods                  []string `json:"basisPeriods" firestore:"basisPeriods"`
	LimitsVersion                 string   `json:"limitsVersion,omitempty" firestore:"limitsVersion,omitempty"`
	LastFullEffectSubscriptionID  string   `json:"lastFullEffectSubscriptionId,omitempty" firestore:"lastFullEffectSubscriptionId,omitempty"`
	LastFullEffectOwnerGeneration int64    `json:"lastFullEffectOwnerGeneration,omitempty" firestore:"lastFullEffectOwnerGeneration,omitempty"`
	LastFullEffectRevision        int64    `json:"lastFullEffectRevision,omitempty" firestore:"lastFullEffectRevision,omitempty"`
	LastFullEffectQuoteKey        string   `json:"lastFullEffectQuoteKey,omitempty" firestore:"lastFullEffectQuoteKey,omitempty"`
	LastProSubscriptionID         string   `json:"lastProSubscriptionId,omitempty" firestore:"lastProSubscriptionId,omitempty"`
	LastProOwnerGeneration        int64    `json:"lastProOwnerGeneration,omitempty" firestore:"lastProOwnerGeneration,omitempty"`
	LastProQuoteKey               string   `json:"lastProQuoteKey,omitempty" firestore:"lastProQuoteKey,omitempty"`
	LastProPlanID                 string   `json:"lastProPlanId,omitempty" firestore:"lastProPlanId,omitempty"`
	LastProPaidServiceProofID     string   `json:"lastProPaidServiceProofId,omitempty" firestore:"lastProPaidServiceProofId,omitempty"`
	// These values come only from the verified payment effect's explicit grants,
	// never the limits resolver's legacy config fallback. Zero means unproved.
	LastProProtectedProjects     int64 `json:"lastProProtectedProjects,omitempty" firestore:"lastProProtectedProjects,omitempty"`
	LastProProtectedProjectUsers int64 `json:"lastProProtectedProjectUsers,omitempty" firestore:"lastProProtectedProjectUsers,omitempty"`
}

PlanApplication is private replay and last-actual-plan-write provenance. Latest applied revision may be basis-only, unlike the last Pro plan write.

type PlanLimits added in v0.4.0

type PlanLimits struct {
	Contributors          int64    `json:"contributors" firestore:"contributors"`
	ProjectGuests         int64    `json:"projectGuests" firestore:"projectGuests"`
	ProjectContributors   *int64   `json:"projectContributors,omitempty" firestore:"projectContributors,omitempty"`
	ProtectedProjects     *int64   `json:"protectedProjects,omitempty" firestore:"protectedProjects,omitempty"`
	ProtectedProjectUsers *int64   `json:"protectedProjectUsers,omitempty" firestore:"protectedProjectUsers,omitempty"`
	AIQuestions           int64    `json:"aiQuestions" firestore:"aiQuestions"`
	AIModelClasses        []string `json:"aiModelClasses" firestore:"aiModelClasses"`
	AIPaysFor             string   `json:"aiPaysFor" firestore:"aiPaysFor"`
}

PlanLimits is the version-1 allowance carried by a paid plan or a response. A Free allowance comes from host configuration, never from a stored plan.

type PlanRecord added in v0.4.0

type PlanRecord struct {
	V                int         `json:"v" firestore:"v"`
	Plan             string      `json:"plan" firestore:"plan"`
	Status           string      `json:"status" firestore:"status"`
	Period           string      `json:"period" firestore:"period"`
	PaidUntil        *time.Time  `json:"paidUntil,omitempty" firestore:"paidUntil,omitempty"`
	EndsAt           *time.Time  `json:"endsAt,omitempty" firestore:"endsAt,omitempty"`
	EndedReason      string      `json:"endedReason,omitempty" firestore:"endedReason,omitempty"`
	Founding         bool        `json:"founding" firestore:"founding"`
	Limits           *PlanLimits `json:"limits,omitempty" firestore:"limits,omitempty"`
	AIExtraQuestions int64       `json:"aiExtraQuestions,omitempty" firestore:"aiExtraQuestions,omitempty"`
	UpdatedAt        *time.Time  `json:"updatedAt,omitempty" firestore:"updatedAt,omitempty"`
}

PlanRecord is the version-1 plan/current document. Test-mode reconciliation writes plan/test instead; readers of live entitlements never use that path.

type Project

type Project struct {
	Title   string                `json:"title" firestore:"title"`
	Access  string                `json:"access,omitempty" firestore:"access,omitempty"`
	UserIDs []string              `json:"userIDs,omitempty" firestore:"userIDs,omitempty"`
	Created *Created              `json:"created,omitempty" firestore:"created,omitempty"`
	Storage string                `json:"storage,omitempty" firestore:"storage,omitempty"`
	Status  string                `json:"status,omitempty" firestore:"status,omitempty"`
	GitHub  *GitHubProjectBinding `json:"github,omitempty" firestore:"github,omitempty"`
}

Project is the data stored in a datatug_projects/{projectID} record.

func NewProjectRecord

func NewProjectRecord(projectID string) (record.Record, *Project)

NewProjectRecord wraps a fresh Project in its dalgo record, returning both the record (for database calls) and the DBO (to populate fields on).

func NewSharedProjectRecord added in v0.10.0

func NewSharedProjectRecord(spaceID, projectID string) (record.Record, *Project)

NewSharedProjectRecord reuses the existing Project DTO without a private userIDs ownership list. The canonical Space path is its ownership binding.

type ProjectAdmission added in v0.11.0

type ProjectAdmission struct {
	OwnerContact                                                                  ProjectOwnerContactProof `json:"ownerContact,omitempty" firestore:"ownerContact,omitempty"`
	Version                                                                       int                      `firestore:"v"`
	Mode, Product, PayerID, ActorID, SpaceID, ProjectID, CommandID, RequestDigest string
	LimitsVersion, SubscriptionID                                                 string
	ProfileVersion, QuotaBasisDigest                                              string
	ProtectedProjectsLimit, ProtectedUsersLimit, QuotaRevision                    int64
	OwnerGeneration                                                               int64
	CreatedAt                                                                     time.Time
	// Version 2 is reserved for a proved Business Space service. Its explicit
	// unlimited grants cannot be inferred from absent finite Pro limits.
	ServiceID, PlanID, PaidServiceProofID string
	OwnerRevision                         int64
	UnlimitedProjects, UnlimitedContacts  bool
}

ProjectAdmission is immutable attribution for future write/AI enforcement. It does not grant membership, included guest AI, or local execution authority.

func NewProjectAdmissionRecord added in v0.11.0

func NewProjectAdmissionRecord(space, project string) (record.Record, *ProjectAdmission)

func (ProjectAdmission) Validate added in v0.11.0

func (a ProjectAdmission) Validate() error

type ProjectBrief

type ProjectBrief struct {
	Title      string `json:"title" firestore:"title"`
	Access     string `json:"access,omitempty" firestore:"access,omitempty"`
	ProjectAPI string `json:"projectApi,omitempty" firestore:"projectApi,omitempty"`
	Branch     string `json:"branch,omitempty" firestore:"branch,omitempty"`
}

ProjectBrief is a brief of one project in a user's DataTug index.

type ProjectOwnerContactProof added in v0.12.0

type ProjectOwnerContactProof struct {
	Version        int                                    `json:"v,omitempty" firestore:"v,omitempty"`
	Contact        contract4linkage.RelationshipEntityRef `json:"contact" firestore:"contact"`
	Role           string                                 `json:"role,omitempty" firestore:"role,omitempty"`
	CatalogVersion string                                 `json:"catalogVersion,omitempty" firestore:"catalogVersion,omitempty"`
}

ProjectOwnerContactProof is immutable paid-create provenance, not another membership list. The actual assignment lives only in the Related graph. Ownerless historical admissions require a separately reviewed migration.

func (ProjectOwnerContactProof) Present added in v0.12.0

func (p ProjectOwnerContactProof) Present() bool

func (ProjectOwnerContactProof) Validate added in v0.12.0

func (p ProjectOwnerContactProof) Validate() error

type ProjectQuotaLimit added in v0.11.0

type ProjectQuotaLimit struct {
	Unlimited bool
	Count     int64
}

ProjectQuotaLimit distinguishes an explicit unlimited grant from absent data. Current Pro admission derives a finite limit from its frozen paid grants.

func (ProjectQuotaLimit) Allows added in v0.11.0

func (l ProjectQuotaLimit) Allows(allocated int64) bool

func (ProjectQuotaLimit) Validate added in v0.11.0

func (l ProjectQuotaLimit) Validate() error

type ProjectRoleCatalogData added in v0.15.0

type ProjectRoleCatalogData struct {
	Version uint16                  `json:"version"`
	Roles   []ProjectRoleDefinition `json:"roles"`
}

func ProjectRoleCatalog added in v0.15.0

func ProjectRoleCatalog() ProjectRoleCatalogData

ProjectRoleCatalog returns the versioned product role catalog. A fresh slice prevents callers from mutating the canonical definitions used by policy.

type ProjectRoleDefinition added in v0.15.0

type ProjectRoleDefinition struct {
	ID                   ProjectRoleID `json:"id"`
	Name                 string        `json:"name"`
	CanBrowse            bool          `json:"canBrowse"`
	CanRunQueries        bool          `json:"canRunQueries"`
	CanEditLocally       bool          `json:"canEditLocally"`
	CanSaveShared        bool          `json:"canSaveShared"`
	CanManageAssignments bool          `json:"canManageAssignments"`
}

ProjectRoleDefinition is the product-owned permission description for a project contact role. Platform and paid-plan guards still apply to each action represented here.

type ProjectRoleID added in v0.15.0

type ProjectRoleID string

ProjectRoleID is a stable role assigned to a contact linked to a standalone DataTug project. These roles are separate from the containing Space roles.

type ProtectedProjectQuota added in v0.11.0

type ProtectedProjectQuota struct {
	Version                             int `firestore:"v"`
	Mode, Product, PayerID, BasisDigest string
	Allocated, Revision                 int64
}

ProtectedProjectQuota retains allocation count across renewals and Space boundaries. Missing records never mean zero. BasisDigest identifies a proved complete empty/imported inventory, not an operator assertion or billing term.

func NewProtectedProjectQuotaRecord added in v0.11.0

func NewProtectedProjectQuotaRecord(mode, product, payer string) (record.Record, *ProtectedProjectQuota)

func (ProtectedProjectQuota) Validate added in v0.11.0

func (q ProtectedProjectQuota) Validate() error

type QueryActivityContext added in v0.20.0

type QueryActivityContext struct {
	Version            int                               `firestore:"v"`
	ContextID          string                            `firestore:"contextID"`
	ActorID            string                            `firestore:"actorID"`
	SpaceID            string                            `firestore:"spaceID"`
	ProjectID          string                            `firestore:"projectID"`
	Period             contract4paymentus.UsagePeriodRef `firestore:"period"`
	PeriodStartUTC     time.Time                         `firestore:"periodStartUTC"`
	PeriodEndUTC       time.Time                         `firestore:"periodEndUTC"`
	PaidUntilUTC       time.Time                         `firestore:"paidUntilUTC"`
	BindingDigest      string                            `firestore:"bindingDigest"`
	PayerBindingDigest string                            `firestore:"payerBindingDigest"`
	PaidBindingProofID string                            `firestore:"paidBindingProofID"`
	QueryUseProofID    string                            `firestore:"queryUseProofID"`
	IssuedAtUTC        time.Time                         `firestore:"issuedAtUTC"`
	ExpiresAtUTC       time.Time                         `firestore:"expiresAtUTC"`
}

QueryActivityContext is private server state. It freezes the first-party reporter, project, paid service, and original metering window without retaining query content or client-supplied financial facts.

func NewQueryActivityContextRecord added in v0.20.0

func NewQueryActivityContextRecord(spaceID, contextID string) (record.Record, *QueryActivityContext)

func (QueryActivityContext) Validate added in v0.20.0

func (c QueryActivityContext) Validate() error

type QueryActivityContextQuota added in v0.20.0

type QueryActivityContextQuota struct {
	Version               int                               `firestore:"v"`
	ActorID               string                            `firestore:"actorID"`
	Period                contract4paymentus.UsagePeriodRef `firestore:"period"`
	ContextWindowStartUTC time.Time                         `firestore:"contextWindowStartUTC"`
	ContextsInWindow      int64                             `firestore:"contextsInWindow"`
	ReportWindowStartUTC  time.Time                         `firestore:"reportWindowStartUTC"`
	ReportsInWindow       int64                             `firestore:"reportsInWindow"`
}

func NewQueryActivityContextQuotaRecord added in v0.20.0

func NewQueryActivityContextQuotaRecord(actorID string, period contract4paymentus.UsagePeriodRef) (record.Record, *QueryActivityContextQuota)

func (QueryActivityContextQuota) Validate added in v0.20.0

func (q QueryActivityContextQuota) Validate() error

type QueryActivityDrainCursor added in v0.23.2

type QueryActivityDrainCursor struct {
	Version      int                     `firestore:"v"`
	Mode         contract4paymentus.Mode `firestore:"mode"`
	SpaceID      string                  `firestore:"spaceID"`
	AfterID      string                  `firestore:"afterID,omitempty"`
	UpdatedAtUTC time.Time               `firestore:"updatedAtUTC"`
}

QueryActivityDrainCursor is Space-scoped operational state. It records a paginated scan position and never authorizes activity or affects billing.

func NewQueryActivityDrainCursorRecord added in v0.23.2

func NewQueryActivityDrainCursorRecord(mode contract4paymentus.Mode, spaceID string) (record.Record, *QueryActivityDrainCursor)

func (QueryActivityDrainCursor) Validate added in v0.23.2

func (c QueryActivityDrainCursor) Validate() error

type QueryActivityKind added in v0.20.0

type QueryActivityKind string
const (
	QueryActivityEdit                QueryActivityKind = "query_edit"
	QueryActivityExecutionDispatched QueryActivityKind = "query_execution_dispatched"
)

func (QueryActivityKind) Valid added in v0.20.0

func (k QueryActivityKind) Valid() bool

type QueryActivityPending added in v0.20.0

type QueryActivityPending struct {
	Version             int                               `firestore:"v"`
	ReceiptID           string                            `firestore:"receiptID"`
	SpaceID             string                            `firestore:"spaceID"`
	Period              contract4paymentus.UsagePeriodRef `firestore:"period"`
	Activity            contract4paymentus.UsageActivity  `firestore:"activity"`
	Sequence            int64                             `firestore:"sequence,omitempty"`
	DeliveryProofDigest string                            `firestore:"deliveryProofDigest,omitempty"`
	DeliveredAtUTC      time.Time                         `firestore:"deliveredAtUTC,omitempty"`
	DeliveryState       string                            `firestore:"deliveryState" json:"deliveryState"`
	Attempts            int64                             `firestore:"attempts"`
	UpdatedAtUTC        time.Time                         `firestore:"updatedAtUTC"`
}

QueryActivityPending is the durable outbox item. It is updated in place and remains until the ledger admits the activity or its closed-period inbox records it, so a crash after ledger commit is safely replayable.

func NewQueryActivityPendingRecord added in v0.20.0

func NewQueryActivityPendingRecord(spaceID, receiptID string) (record.Record, *QueryActivityPending)

func (QueryActivityPending) Validate added in v0.20.0

func (p QueryActivityPending) Validate() error

type QueryActivityPeriodCheckpoint added in v0.23.1

type QueryActivityPeriodCheckpoint struct {
	Version           int                                    `firestore:"v"`
	Period            contract4paymentus.UsagePeriodRef      `firestore:"period"`
	Snapshot          contract4paymentus.UsagePeriodSnapshot `firestore:"snapshot"`
	AnchorUTC         time.Time                              `firestore:"anchorUTC"`
	AnchorProofDigest string                                 `firestore:"anchorProofDigest"`
	State             string                                 `firestore:"state"`
	CloseRequest      contract4paymentus.UsageCloseRequest   `firestore:"closeRequest,omitempty"`
	AcceptedCount     int64                                  `firestore:"acceptedCount"`
	DeliveredThrough  int64                                  `firestore:"deliveredThrough"`
	UpdatedAtUTC      time.Time                              `firestore:"updatedAtUTC"`
}

QueryActivityPeriodCheckpoint is the explicit completeness fence for one anchored Business usage period. A missing record is never interpreted as an empty period. The checkpoint is prepared before Paymentus.Open and becomes ready only after that ledger operation and a same-transaction read confirm the exact stored snapshot.

func NewQueryActivityPeriodCheckpointRecord added in v0.23.1

func NewQueryActivityPeriodCheckpointRecord(period contract4paymentus.UsagePeriodRef) (record.Record, *QueryActivityPeriodCheckpoint)

func (QueryActivityPeriodCheckpoint) Validate added in v0.23.1

func (c QueryActivityPeriodCheckpoint) Validate() error

type QueryActivityPeriodSequence added in v0.23.1

type QueryActivityPeriodSequence struct {
	Version             int                               `firestore:"v"`
	Period              contract4paymentus.UsagePeriodRef `firestore:"period"`
	Sequence            int64                             `firestore:"sequence"`
	ReceiptID           string                            `firestore:"receiptID"`
	ActivityDigest      string                            `firestore:"activityDigest"`
	DeliveryState       string                            `firestore:"deliveryState"`
	DeliveryProofDigest string                            `firestore:"deliveryProofDigest,omitempty"`
	DeliveredAtUTC      time.Time                         `firestore:"deliveredAtUTC,omitempty"`
}

QueryActivityPeriodSequence maps a period-local accepted sequence to its immutable receipt. Delivery proof is recorded only after Paymentus admits the exact activity or the correction inbox durably retains it.

func NewQueryActivityPeriodSequenceRecord added in v0.23.1

func NewQueryActivityPeriodSequenceRecord(period contract4paymentus.UsagePeriodRef, sequence int64) (record.Record, *QueryActivityPeriodSequence)

func (QueryActivityPeriodSequence) Validate added in v0.23.1

func (s QueryActivityPeriodSequence) Validate() error

type QueryActivityReceipt added in v0.20.0

type QueryActivityReceipt struct {
	Version            int                               `firestore:"v"`
	ReceiptID          string                            `firestore:"receiptID"`
	ContextID          string                            `firestore:"contextID"`
	OperationID        string                            `firestore:"operationID"`
	Kind               QueryActivityKind                 `firestore:"kind"`
	ActorID            string                            `firestore:"actorID"`
	SpaceID            string                            `firestore:"spaceID"`
	ProjectID          string                            `firestore:"projectID"`
	Period             contract4paymentus.UsagePeriodRef `firestore:"period"`
	PeriodStartUTC     time.Time                         `firestore:"periodStartUTC"`
	PeriodEndUTC       time.Time                         `firestore:"periodEndUTC"`
	PaidUntilUTC       time.Time                         `firestore:"paidUntilUTC"`
	Activity           contract4paymentus.UsageActivity  `firestore:"activity"`
	BindingDigest      string                            `firestore:"bindingDigest"`
	PayerBindingDigest string                            `firestore:"payerBindingDigest"`
	PaidBindingProofID string                            `firestore:"paidBindingProofID"`
	QueryUseProofID    string                            `firestore:"queryUseProofID"`
	AcceptedAtUTC      time.Time                         `firestore:"acceptedAtUTC"`
	StructuralDigest   string                            `firestore:"structuralDigest"`
}

QueryActivityReceipt coalesces the first qualifying reported action for one actor and canonical payer/service period. ContextID, OperationID and Kind are the immutable operation binding; the structural digest contains only server-derived facts, never query text, results, or request data.

func NewQueryActivityReceiptRecord added in v0.20.0

func NewQueryActivityReceiptRecord(actorID string, period contract4paymentus.UsagePeriodRef) (record.Record, *QueryActivityReceipt)

func (QueryActivityReceipt) Validate added in v0.20.0

func (r QueryActivityReceipt) Validate() error

type QueryEditCandidate added in v0.18.0

type QueryEditCandidate struct {
	Version        int       `firestore:"v"`
	SourceID       string    `firestore:"sourceID"`
	EventID        string    `firestore:"eventID"`
	ActorID        string    `firestore:"actorID"`
	OperationID    string    `firestore:"operationID"`
	SpaceID        string    `firestore:"spaceID"`
	ProjectID      string    `firestore:"projectID"`
	RepositoryID   int64     `firestore:"repositoryID"`
	Folder         string    `firestore:"folder"`
	ExpectedHead   string    `firestore:"expectedHead"`
	QueryPath      string    `firestore:"queryPath"`
	BodyChanged    bool      `firestore:"bodyChanged"`
	Classification string    `firestore:"classification"`
	AcceptedAtUTC  time.Time `firestore:"acceptedAtUTC"`
}

QueryEditCandidate is private, server-accepted evidence of a changed query body submitted by an authorized actor. It is unclassified for billing: a provider failure, stale later commit, or abandoned save does not promote it. Query text and text-derived digests are deliberately absent.

func NewQueryEditCandidateRecord added in v0.18.0

func NewQueryEditCandidateRecord(spaceID, actorID, operationID string) (record.Record, *QueryEditCandidate)

func (QueryEditCandidate) Validate added in v0.18.0

func (c QueryEditCandidate) Validate() error

type SharedLinkedProject added in v0.12.0

type SharedLinkedProject struct {
	Project
	contract4linkage.WithRelatedAndIDs
}

SharedLinkedProject reuses Linkage's persisted graph at the existing shared project key. Legacy private Project/UserIDs remain unchanged; shared access never derives from that legacy list.

func NewSharedLinkedProjectRecord added in v0.12.0

func NewSharedLinkedProjectRecord(space, project string) (record.Record, *SharedLinkedProject)

type SharedProjectCreateReceipt added in v0.10.0

type SharedProjectCreateReceipt struct {
	OwnerContact  ProjectOwnerContactProof `json:"ownerContact,omitempty" firestore:"ownerContact,omitempty"`
	Version       int                      `json:"v" firestore:"v"`
	ActorID       string                   `json:"actorID" firestore:"actorID"`
	SpaceID       string                   `json:"spaceID" firestore:"spaceID"`
	CommandID     string                   `json:"commandID" firestore:"commandID"`
	Title         string                   `json:"title" firestore:"title"`
	RequestDigest string                   `json:"requestDigest" firestore:"requestDigest"`
	ProjectID     string                   `json:"projectID" firestore:"projectID"`
	CreatedAt     time.Time                `json:"createdAt" firestore:"createdAt"`
	PayerID       string                   `json:"payerID,omitempty" firestore:"payerID,omitempty"`
	Mode          string                   `json:"mode,omitempty" firestore:"mode,omitempty"`
	Product       string                   `json:"product,omitempty" firestore:"product,omitempty"`
	GitHub        *GitHubCreateSource      `json:"github,omitempty" firestore:"github,omitempty"`
}

SharedProjectCreateReceipt is immutable, private command evidence. It is not a project index, a module-enablement record, or a billing entitlement.

func NewSharedProjectCreateReceiptRecord added in v0.10.0

func NewSharedProjectCreateReceiptRecord(spaceID, commandID string) (record.Record, *SharedProjectCreateReceipt)

func (SharedProjectCreateReceipt) Validate added in v0.10.0

func (r SharedProjectCreateReceipt) Validate() error

type SharedProjectQuery added in v0.27.0

type SharedProjectQuery struct {
	Version    int                            `json:"v" firestore:"v"`
	SpaceID    string                         `json:"spaceID" firestore:"spaceID"`
	ProjectID  string                         `json:"projectID" firestore:"projectID"`
	FolderPath string                         `json:"folderPath" firestore:"folderPath"`
	QueryID    string                         `json:"queryID" firestore:"queryID"`
	Query      datatug.QueryDefWithFolderPath `json:"query" firestore:"query"`
	Revision   string                         `json:"revision" firestore:"revision"`
	UpdatedAt  time.Time                      `json:"updatedAt" firestore:"updatedAt"`
}

SharedProjectQuery stores a complete query definition atomically. Unlike a Git-backed project it has no branch; Revision is an opaque content revision.

func NewSharedProjectQueryRecord added in v0.27.0

func NewSharedProjectQueryRecord(spaceID, projectID, folderPath, queryID string) (record.Record, *SharedProjectQuery)

func (SharedProjectQuery) Validate added in v0.27.0

func (q SharedProjectQuery) Validate() error

type SharedProjectQuerySaveReceipt added in v0.27.0

type SharedProjectQuerySaveReceipt struct {
	Version       int                   `json:"v" firestore:"v"`
	ActorID       string                `json:"actorID" firestore:"actorID"`
	SpaceID       string                `json:"spaceID" firestore:"spaceID"`
	ProjectID     string                `json:"projectID" firestore:"projectID"`
	OperationID   string                `json:"operationID" firestore:"operationID"`
	Kind          string                `json:"kind" firestore:"kind"`
	RequestDigest string                `json:"requestDigest" firestore:"requestDigest"`
	Result        dto.SaveQueryResponse `json:"result" firestore:"result"`
	CreatedAtUTC  time.Time             `json:"createdAtUTC" firestore:"createdAtUTC"`
}

SharedProjectQuerySaveReceipt is immutable idempotency evidence. Space and project are separate fields so a receipt cannot be rebound across scopes.

func NewSharedProjectQuerySaveReceiptRecord added in v0.27.0

func NewSharedProjectQuerySaveReceiptRecord(spaceID, projectID, actorID, operationID string) (record.Record, *SharedProjectQuerySaveReceipt)

func (SharedProjectQuerySaveReceipt) Validate added in v0.27.0

func (r SharedProjectQuerySaveReceipt) Validate() error

type SharedProjectRef added in v0.10.0

type SharedProjectRef struct {
	StoreID   string `json:"storeId"`
	SpaceID   string `json:"spaceID"`
	ProjectID string `json:"projectId"`
}

SharedProjectRef preserves the distinction between a Space-owned project and the legacy private cloud root, even when their project IDs are equal.

type StoreBrief

type StoreBrief struct {
	Title    string                   `json:"title" firestore:"title"`
	Type     string                   `json:"type" firestore:"type"`
	URL      string                   `json:"url,omitempty" firestore:"url,omitempty"`
	Projects map[string]*ProjectBrief `json:"projects,omitempty" firestore:"projects,omitempty"`
}

StoreBrief is a brief of one store in a user's DataTug index.

type UserExt

type UserExt struct {
	Stores map[string]*StoreBrief `json:"stores,omitempty" firestore:"stores,omitempty"`
}

UserExt is the DataTug extension data of one user: the index of the DataTug stores the user can see, and the project briefs inside each of them. It is the data of the users/{userID}/ext/datatug record.

func NewUserExtRecord

func NewUserExtRecord(userID, extID string) (record.Record, *UserExt)

NewUserExtRecord wraps a fresh UserExt in its dalgo record, returning both the record and the DBO.

Jump to

Keyboard shortcuts

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