Documentation
¶
Overview ¶
Package quicksearch4datatug implements consent-controlled project metadata search.
Index ¶
- Constants
- Variables
- func CanonicalProjectKey(project string) string
- func EqualMetadata(uploaded, canonical Document) bool
- func Fold(s string) string
- func IsSchemaMetadataPath(file string) bool
- func IsSearchPath(ctx context.Context) bool
- func MetadataTags(tags []string) []string
- func RawTags(value any) []string
- func ReadBatch(ctx context.Context, count int, read func(int) error) []error
- func StateKey(key string) *record.Key
- func TagKey(tag string) string
- type Access
- type Authority
- type BatchAuthority
- type CleanupAuthority
- type Coverage
- type DALStore
- type Document
- func InlineSchemaDocument(body []byte, d Document) (Document, error)
- func NamedDocument(kind, id, title string, tags []string, ref Reference) Document
- func NamedDocumentJSON(kind, id string, body []byte, ref Reference) (Document, error)
- func SchemaDocument(modelID, modelTitle, schema, table, column, parentKind string, tags []string) Document
- func SchemaDocumentFromSource(read func(string) ([]byte, error), d Document) (Document, error)
- func SchemaInventory(paths []string, read func(string) ([]byte, error)) ([]Document, error)
- func SplitSchemaDocuments(model, schema, table, kind string, body []byte) ([]Document, error)
- type FirestoreStore
- type MetadataAuthority
- type MetadataSnapshot
- type PreviewRequest
- type Provider
- type ProviderDocument
- type ProviderSearchRequest
- type PublicGitHubVerifier
- func (v *PublicGitHubVerifier) ReadFile(ctx context.Context, repo PublicRepository, branch, file string) ([]byte, error)
- func (v *PublicGitHubVerifier) Resolve(ctx context.Context, owner, name, folder, branch string) (PublicRepository, error)
- func (v *PublicGitHubVerifier) ResolveRepository(ctx context.Context, owner, name, folder, branch string) (PublicRepository, error)
- type PublicRepository
- type Query
- type Reference
- type Results
- type Scope
- type Service
- func (s *Service) CurrentOperation(ctx context.Context, canonical Scope) (WriterOperation, error)
- func (s *Service) CurrentWriter(ctx context.Context, canonical Scope) (string, time.Time, error)
- func (s *Service) Disable(ctx context.Context, actor string, scope Scope) (Status, error)
- func (s *Service) Index(ctx context.Context, actor string, scope Scope, snapshot Snapshot, enable bool) (Status, error)
- func (s *Service) Preview(ctx context.Context, actor string, scope Scope, request PreviewRequest) (MetadataSnapshot, error)
- func (s *Service) RecoverWriter(ctx context.Context, scope Scope, operation string, ...) error
- func (s *Service) Search(ctx context.Context, actor string, scope Scope, q Query) (Results, error)
- func (s *Service) Status(ctx context.Context, actor string, scope Scope) (Status, error)
- type Snapshot
- type State
- type Status
- type Store
- type Timings
- type TransactionalStore
- type Typesense
- func (t *Typesense) CredentialGeneration() string
- func (t *Typesense) Delete(ctx context.Context, collection string) error
- func (t *Typesense) Read(ctx context.Context, collection string) ([]ProviderDocument, error)
- func (t *Typesense) Replace(ctx context.Context, collection string, docs []ProviderDocument) error
- func (t *Typesense) Search(ctx context.Context, collection string, req ProviderSearchRequest) ([]ProviderDocument, error)
- type TypesenseOptions
- type WriterOperation
- type WriterRecoveryBarrier
Constants ¶
const ConsentVersion = "project-quick-search/1"
const GitHubBudgetPerHour = 2000
GitHubBudgetPerHour keeps headroom in the server-owned OAuth app quota (5,000/hour).
const MaxDocuments = 1000
const MaxKnownScopes = 256
A repository catalogue bounds only this repository/folder; other customers cannot exhaust its capacity. Entries remain until physical deletion is known.
const MaxTrackedCollections = 128
Bound failed cleanup resources before creating another provider collection.
const ReadConcurrency = 8
ReadConcurrency bounds independent source reads within one request.
const SearchSchemaVersion = 2
SearchSchemaVersion is the collection schema that supports provider-side matching. An absent persisted version means version 1 (export-based, no longer served).
Variables ¶
var ( ErrInvalid = errors.New("invalid_request") ErrDenied = errors.New("project_denied") ErrConflict = errors.New("operation_in_progress") ErrCapacity = errors.New("index_capacity_reached") ErrConsent = errors.New("consent_required") ErrProvider = errors.New("provider_unavailable") ErrProviderUnknown = errors.New("provider_completion_unknown") // ErrReindexRequired: the active generation predates provider-side search. // ErrRateLimited: per-instance abuse limits were exceeded before any upstream call. ErrRateLimited = errors.New("quick_search_rate_limited") ErrReindexRequired = errors.New("quick_search_reindex_required") // ErrUnsupportedStorage: provider-backed search does not serve hosted projects yet. ErrUnsupportedStorage = errors.New("quick_search_unsupported_storage") )
Functions ¶
func CanonicalProjectKey ¶
CanonicalProjectKey lowercases only the owner and repository of a "repo@owner@folder" project key: GitHub names are case-insensitive, repository paths are not.
func EqualMetadata ¶
EqualMetadata compares the entire uploaded projection, including navigation. No provider-controlled name/tag/source label survives an existence-only check.
func IsSchemaMetadataPath ¶
IsSchemaMetadataPath selects exactly supported model descriptors and split columns wrappers, excluding DDL and unrelated model files.
func IsSearchPath ¶
IsSearchPath reports whether the authority is being resolved for a search request, which needs repository visibility and the actor's read access but not the manifest or management rights.
func MetadataTags ¶
func ReadBatch ¶
ReadBatch joins all workers before returning input-ordered outcomes. Readers must be concurrency safe; cancellation prevents further source calls.
Types ¶
type Access ¶
type Access struct {
Scope Scope
CanManage, Eligible bool
Audience string
GitHubOwner, GitHubName string
// OwnerID is the immutable GitHub owner ID of a public repository (0 otherwise).
OwnerID int64
// DefaultBranch is the repository's current default branch when known.
DefaultBranch string
// registration that authorized it; both are empty for public repositories.
RegisteredSpaceID, SharedProjectID string
}
Access is always server-derived, including the immutable canonical scope.
type BatchAuthority ¶
BatchAuthority optionally supports safe bounded source admission. Authorities without this port retain their sequential admission contract.
type CleanupAuthority ¶
CleanupAuthority grants only deletion of retained metadata, independently of source read access.
type DALStore ¶
DALStore reuses the host's server-owned database and transaction lifecycle.
type Document ¶
type Document struct {
Kind string `json:"kind"`
ID string `json:"id"`
Name string `json:"name"`
QualifiedName string `json:"qualifiedName,omitempty"`
SourceName string `json:"sourceName,omitempty"`
ParentID string `json:"parentId,omitempty"`
ParentName string `json:"parentName,omitempty"`
Tags []string `json:"tags"`
Reference Reference `json:"reference"`
}
func NamedDocument ¶
func NamedDocumentJSON ¶
func SchemaDocument ¶
func SchemaDocumentFromSource ¶
SchemaDocumentFromSource is shared by current-source per-item admission.
func SchemaInventory ¶
SchemaInventory consumes an already complete, pinned project file inventory.
func SplitSchemaDocuments ¶
type FirestoreStore ¶
FirestoreStore keeps lifecycle authority server-side; it stores no indexed metadata.
func (FirestoreStore) UpdateMany ¶
type MetadataAuthority ¶
type MetadataAuthority interface {
ReadMetadata(context.Context, string, Access, string) (MetadataSnapshot, error)
}
MetadataAuthority reads current canonical metadata without changing index state.
type MetadataSnapshot ¶
type PreviewRequest ¶
type PreviewRequest struct {
EnvironmentID string `json:"environmentId,omitempty"`
}
type Provider ¶
type Provider interface {
Replace(context.Context, string, []ProviderDocument) error
// Search performs matching in the engine over a bounded collection.
Search(context.Context, string, ProviderSearchRequest) ([]ProviderDocument, error)
// Read exports the whole collection; maintenance and migration only, never on the search path.
Read(context.Context, string) ([]ProviderDocument, error)
Delete(context.Context, string) error
}
type ProviderDocument ¶
type ProviderSearchRequest ¶
type ProviderSearchRequest struct {
Partition string
Query string
Generation uint64
TagKeys []string
}
ProviderSearchRequest is engine-agnostic: Query is already folded, TagKeys are TagKey values (never raw tag text) and Generation selects the published documents. The adapter owns paging and must return the complete matched set.
type PublicGitHubVerifier ¶
type PublicGitHubVerifier struct {
// contains filtered or unexported fields
}
func NewPublicGitHubVerifier ¶
func NewPublicGitHubVerifier(client *http.Client) *PublicGitHubVerifier
func (*PublicGitHubVerifier) ReadFile ¶
func (v *PublicGitHubVerifier) ReadFile(ctx context.Context, repo PublicRepository, branch, file string) ([]byte, error)
func (*PublicGitHubVerifier) Resolve ¶
func (v *PublicGitHubVerifier) Resolve(ctx context.Context, owner, name, folder, branch string) (PublicRepository, error)
Resolve verifies live public visibility and that the folder holds a DataTug project manifest.
func (*PublicGitHubVerifier) ResolveRepository ¶
func (v *PublicGitHubVerifier) ResolveRepository(ctx context.Context, owner, name, folder, branch string) (PublicRepository, error)
ResolveRepository is the one-call search-path check: live repository identity and public visibility (404 denies; 401/403/429/5xx and transport errors are unavailable). It does not read the project manifest.
type PublicRepository ¶
type Reference ¶
type Reference struct {
EnvironmentID string `json:"environmentId,omitempty"`
SourceID string `json:"sourceId,omitempty"`
DBModelID string `json:"dbModelId,omitempty"`
Schema string `json:"schema,omitempty"`
Table string `json:"table,omitempty"`
Column string `json:"column,omitempty"`
ObjectID string `json:"objectId,omitempty"`
Folder string `json:"folder,omitempty"`
}
type Scope ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) CurrentOperation ¶
func (*Service) CurrentWriter ¶
CurrentWriter is trusted host recovery information, never a browser API.
func (*Service) Preview ¶
func (s *Service) Preview(ctx context.Context, actor string, scope Scope, request PreviewRequest) (MetadataSnapshot, error)
func (*Service) RecoverWriter ¶
type Snapshot ¶
type State ¶
type State struct {
CatalogueInitialized bool
KnownScopes []Scope
CleanupEpoch uint64
CredentialGeneration string
Scope Scope
Generation uint64
ConsentActor string
ConsentAt time.Time
ConsentVersion string
Phase string
Active string
ActiveGeneration uint64
Collections []string
CleanupOwners map[string]string
Lease string
LeaseUntil time.Time
LastIndexedAt *time.Time
Count int
Coverage []Coverage
Error string
// SchemaVersion is the provider collection schema of the active generation (absent = 1).
SchemaVersion int `json:",omitempty"`
// RegisteredSpaceID and SharedProjectID are the private registration persisted at publication.
RegisteredSpaceID string `json:",omitempty"`
// OwnerID is the public repository owner ID observed at publication.
OwnerID int64 `json:",omitempty"`
// NameKeys lists the anonymous name-index entries written for this scope at publication.
NameKeys []string `json:",omitempty"`
}
type Status ¶
type Status struct {
SupportsMetadataPreview bool `json:"supportsMetadataPreview,omitempty"`
State string `json:"state"`
CanManage bool `json:"canManage"`
Eligible bool `json:"eligible"`
Audience string `json:"audience"`
Provider string `json:"provider"`
ConsentVersion string `json:"consentVersion,omitempty"`
LastIndexedAt *time.Time `json:"lastIndexedAt,omitempty"`
DocumentCount int `json:"documentCount"`
Error string `json:"error,omitempty"`
SourceCoverage []Coverage `json:"sourceCoverage"`
Revision uint64 `json:"revision"`
SchemaVersion int `json:"schemaVersion,omitempty"`
// ("not_eligible", "unsupported_storage"); zero is never reported as truth.
CountsUnavailable string `json:"countsUnavailable,omitempty"`
// Warning is "default_branch_changed" for a manager when no consented scope covers the
// repository's current default branch.
Warning string `json:"warning,omitempty"`
}
func (Status) MarshalJSON ¶
MarshalJSON omits every count when CountsUnavailable is set.
type Store ¶
type Store interface {
Update(context.Context, string, func(*State) error) error
Read(context.Context, string) (State, error)
}
Store serializes mutations durably across processes. A missing scope is a zero State.
type Timings ¶
type Timings struct {
// contains filtered or unexported fields
}
Timings records stage durations only: no query text, scope, metadata or tokens.
func WithTimings ¶
WithTimings returns a context whose Service calls record stage durations into the recorder.
type TransactionalStore ¶
type TransactionalStore interface {
UpdateMany(context.Context, []string, func(map[string]*State) error) error
}
TransactionalStore atomically validates the repository catalogue and claims lifecycle state.
type Typesense ¶
type Typesense struct {
// contains filtered or unexported fields
}
func NewTypesense ¶
func NewTypesense(o TypesenseOptions) (*Typesense, error)
func (*Typesense) CredentialGeneration ¶
func (*Typesense) Read ¶
Read exports the bounded collection. Maintenance and migration only: Search and Status never call it.
func (*Typesense) Search ¶
func (t *Typesense) Search(ctx context.Context, collection string, req ProviderSearchRequest) ([]ProviderDocument, error)
Search pages sequentially so a same-name group is never split, failing closed when the total exceeds the document cap or changes between pages.
type TypesenseOptions ¶
type TypesenseOptions struct {
Origin, APIKey, CollectionPrefix string
SearchAPIKey string
CredentialGeneration string
HTTPClient *http.Client
}
TypesenseOptions: APIKey is the scoped lifecycle credential (create, import, export, delete). SearchAPIKey is a separate search-only credential; without it Search is unavailable while lifecycle operations keep working.
type WriterOperation ¶
type WriterOperation struct {
ID string
CredentialGeneration string
LeaseUntil time.Time
Scope Scope
}
WriterOperation is trusted maintenance information, never exposed by routes.
type WriterRecoveryBarrier ¶
WriterRecoveryBarrier must prove the old process/operation cannot issue any further provider requests (for example after an authoritative instance kill). Lease expiry or a caller assertion alone is not a recovery barrier.