models4datatug

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package models4datatug holds this extension's database objects and the dalgo keys they are stored under. Like the rest of the module it depends on dal-go only — no database client, no platform package.

Index

Constants

View Source
const (
	SpacesCollection  = "spaces"
	PlanCollection    = "plan"
	AIUsageCollection = "aiUsage"
)
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"
)

Variables

This section is empty.

Functions

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 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 NewProjectKey

func NewProjectKey(projectID string) *record.Key

NewProjectKey builds the dalgo key of a project record.

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}.

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 Created

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

Created holds the creation timestamp of a DataTug record.

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"`
	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"`
}

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).

type ProjectBrief

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

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

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