Documentation
¶
Overview ¶
Package store is AudioSmith's persistence contract: repositories for each kind of record, behind which the database lives. The app uses internal/store/sqlitestore (SQLite through the MyGo plugin github.com/egoist/mygo/plugins/sqlite; schema in its migrations/*.sql), which imports the MVP's history.json on first run with internal/store/historyjson (an implementation of Takes alone, kept for that import and for tests).
Rules:
- Repositories are goroutine-safe and may block on I/O: never call them from a MyGo build pass. The service layer (internal/services) is their only caller once it exists; the UI goes through services.
- Values in, values out: a repository copies what it is given and returns copies.
- Not found is an error wrapping core.ErrNotFound.
- Blobs (audio, portraits, voice prompts) are files under the store's directories, referenced by name; the store deletes a record's files with the record.
Imports: core, jobs.
Index ¶
- Constants
- type CallQuery
- type CallRecord
- type Calls
- type Documents
- type DubQuery
- type DubRecord
- type Dubs
- type Exports
- type Favorites
- type Library
- type LibraryItem
- type LibraryQuery
- type Licences
- type Projects
- type RenderQuery
- type Renders
- type Segment
- type Store
- type Takes
- type Transcripts
- type VoiceLinks
- type Voices
- type WorkflowRecord
- type Workflows
Constants ¶
const ( LibAll = "" LibDub = "dub" LibStory = "story" LibAudiobook = "audiobook" LibVoice = "voice" LibTranscript = "transcript" LibTake = "take" LibExport = "export" )
Library categories: the filters of the Projects page.
const LibCall = "call"
LibCall is the Projects page's category of phone calls (M6b).
const LibWorkflow = "workflow"
LibWorkflow is the Projects page's category of workflows (M6).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallRecord ¶
type CallRecord struct {
ID string
CreatedAt time.Time
UpdatedAt time.Time
Direction string // "outbound" | "inbound"
Number string // the other party's number (E.164)
Title string // the brief's first line, for lists
Status string // the service's phase: dialing, ringing, live, ended, failed
Outcome string // booked, done, not_done, needs_you, failed, or ""
Summary string
// ProviderSID is Twilio's Call SID.
ProviderSID string
Duration float64 // seconds talked
// Doc is the call document; List leaves it nil.
Doc json.RawMessage
}
CallRecord is a phone call as the store keeps it (M6b): the document the calls service owns (services.Call as JSON: brief, voice, disclosure, transcript, timeline, latency; the store does not read it) and the columns lists show, filter and search on.
type Calls ¶
type Calls interface {
Put(ctx context.Context, r CallRecord) error
Get(ctx context.Context, id string) (CallRecord, error)
// BySID finds a call by Twilio's Call SID (core.ErrNotFound).
BySID(ctx context.Context, sid string) (CallRecord, error)
// List returns calls, most recent first, without documents.
List(ctx context.Context, q CallQuery) ([]CallRecord, error)
Delete(ctx context.Context, id string) error
// Dir is where the calls' files (recordings) live. Pure.
Dir() string
}
Calls stores phone calls. Like Dubs, it is not part of Store: sqlitestore.(*Store).Calls returns it.
type Documents ¶
type Documents interface {
// Get returns the document and whether it exists.
Get(ctx context.Context, key string) ([]byte, bool, error)
Put(ctx context.Context, key string, doc []byte) error
Delete(ctx context.Context, key string) error
}
Documents is a key → JSON store for small documents.
type DubQuery ¶
type DubQuery struct {
// Batch lists one batch queue's projects; "" the Dub page's.
Batch string
// AllBatches lists every project (Batch is ignored).
AllBatches bool
Limit int
Offset int
}
DubQuery selects dub projects to list.
type DubRecord ¶
type DubRecord struct {
ID string
CreatedAt time.Time
UpdatedAt time.Time
// Batch is the batch queue the project belongs to ("" = the Dub page's).
Batch string
Title string
Source string // the source's path or URL
Languages []string // the target languages
Phase string // the service's summary of where the project is
Duration float64 // the source's length, seconds
// Doc is the project document; List leaves it nil.
Doc json.RawMessage
}
DubRecord is a dub project as the store keeps it (M4): the document the dub service owns (internal/dub.Project as JSON; the store does not read it) and the columns lists show and filter on.
type Dubs ¶
type Dubs interface {
Put(ctx context.Context, r DubRecord) error
Get(ctx context.Context, id string) (DubRecord, error)
// List returns matching projects, most recently changed first,
// without their documents.
List(ctx context.Context, q DubQuery) ([]DubRecord, error)
Delete(ctx context.Context, id string) error
// Dir is where the projects' files live (<dir>/<id>/). Pure.
Dir() string
}
Dubs stores dub projects. Like Transcripts, it is not part of Store: sqlitestore.(*Store).Dubs returns it.
type Exports ¶
type Exports interface {
Put(ctx context.Context, e core.Export) error
Get(ctx context.Context, id string) (core.Export, error)
// List returns the records whose title or path matches search ("" =
// all), newest first; limit 0 = no limit.
List(ctx context.Context, search string, limit int) ([]core.Export, error)
Delete(ctx context.Context, id string) error
}
Exports stores export records (core.Export).
type Favorites ¶
type Favorites interface {
List(ctx context.Context, scope string) ([]string, error)
// Set adds (on) or removes a key; both are idempotent.
Set(ctx context.Context, scope, key string, on bool) error
}
Favorites stores sets of favorite keys by scope ("gallery": archetype ids, later "community:<repo>:<id>").
type Library ¶
type Library interface {
Search(ctx context.Context, q LibraryQuery) ([]LibraryItem, error)
// Counts returns how many items each category has for search (the
// key "" is the total).
Counts(ctx context.Context, search string) (map[string]int, error)
}
Library searches across the stores.
type LibraryItem ¶
type LibraryItem struct {
Source string // "project", "render", "voice", "take", "export"
ID string
Category string // the Lib* category it is listed under
Title string
// Detail is a second line chosen by source: a project's summary JSON,
// a render's state, a voice's kind, a take's model, an export's path.
Detail string
Updated time.Time
}
LibraryItem is one row of the library: a project, a finished render, a voice, a take or an export record.
type LibraryQuery ¶
type LibraryQuery struct {
Category string // a Lib* category; "" = all
Search string // full text over titles, scripts, names, paths
Limit int // 0 = no limit
Offset int
}
LibraryQuery selects library items.
type Licences ¶
type Licences interface {
Put(ctx context.Context, a core.LicenceAcceptance) error
Delete(ctx context.Context, licence, model string) error
List(ctx context.Context) ([]core.LicenceAcceptance, error)
}
Licences stores licence acceptances.
type Projects ¶
type Projects interface {
Put(ctx context.Context, p core.Project) error
Get(ctx context.Context, id string) (core.Project, error)
List(ctx context.Context, kind core.ProjectKind, search string) ([]core.Project, error)
Delete(ctx context.Context, id string) error
// PutSummary stores what the library shows of a project without
// reading its body (JSON: lines, words, voices…), and its segments:
// they replace the project's segments, so "where this voice has been
// used" counts them. A segment's voice that no longer exists is kept
// as none.
PutSummary(ctx context.Context, id string, summary []byte, segs []Segment) error
}
Projects stores projects; segments, renders and exports are rows of their own tables keyed by project id (see sqlitestore/migrations) with repositories added by the milestone that needs them.
type RenderQuery ¶
type RenderQuery struct {
ProjectID string
States []core.RenderState
Auditions bool // include auditions
Limit int
// Light lists bodies holding only their "output" (where the book
// is), rather than whole bodies with the book's manifest (1 MB for a
// long book; code review 1102 perf M4); a render of no project keeps
// its whole body (its title is its script's first words).
Light bool
}
RenderQuery selects renders: the zero value is every render but auditions, newest first.
type Renders ¶
type Renders interface {
Put(ctx context.Context, r core.Render) error
Get(ctx context.Context, id string) (core.Render, error)
List(ctx context.Context, q RenderQuery) ([]core.Render, error)
Delete(ctx context.Context, id string) error
}
Renders stores longform renders (core.Render).
type Segment ¶
Segment is a row of a project's segments (story lines, audiobook chapters, dub cues): what it says and with which voice.
type Store ¶
type Store interface {
Takes() Takes
Voices() Voices
Projects() Projects
Licences() Licences
// Documents holds small JSON documents by key: "settings:app" (the
// settings.Settings document) and "draft:<page>" (core.DraftService).
Documents() Documents
Favorites() Favorites
// Renders and Exports are the longform renders and the export
// records (M3); Library searches every kind of record at once.
Renders() Renders
Exports() Exports
Library() Library
Jobs() jobs.Store
Close() error
}
Store is the whole database. Methods returning a repository never fail; a store that lacks one returns a repository whose methods fail with core.ErrUnsupported.
type Takes ¶
type Takes interface {
// Put inserts or replaces a take (by ID). Its audio file must already
// be in AudioDir.
Put(ctx context.Context, t core.Take) error
Get(ctx context.Context, id string) (core.Take, error)
// List returns matching takes, newest first.
List(ctx context.Context, q core.TakeQuery) ([]core.Take, error)
// Delete removes the take and its audio file.
Delete(ctx context.Context, id string) error
// AudioDir is the directory take audio lives in (the engine writes
// there). AudioPath joins it with t.File. Both are pure.
AudioDir() string
AudioPath(t core.Take) string
}
Takes stores takes and their audio files.
type Transcripts ¶
type Transcripts interface {
// Put inserts or replaces a transcript (by ID). Its audio file, if
// any, must already be in AudioDir.
Put(ctx context.Context, t core.Transcript) error
// Get returns the whole transcript, word timings included.
Get(ctx context.Context, id string) (core.Transcript, error)
// List returns matching transcripts, newest first, without word
// timings (Get has them).
List(ctx context.Context, q core.TranscriptQuery) ([]core.Transcript, error)
// Delete removes the transcript and its audio file.
Delete(ctx context.Context, id string) error
// AudioDir is where transcript audio lives; AudioPath joins it with
// t.Audio ("" when there is none). Both are pure.
AudioDir() string
AudioPath(t core.Transcript) string
}
Transcripts stores transcripts (M2) and the audio kept with them. It is not part of Store, so the milestones that add repositories don't touch the same interface: sqlitestore.(*Store).Transcripts returns it.
type VoiceLinks ¶
type VoiceLinks struct {
Takes []string `json:"takes,omitempty"`
Segments []string `json:"segments,omitempty"`
}
VoiceLinks are the ids of the takes and project segments that use a voice.
type Voices ¶
type Voices interface {
Put(ctx context.Context, v core.Voice) error
Get(ctx context.Context, id string) (core.Voice, error)
List(ctx context.Context, q core.VoiceQuery) ([]core.Voice, error)
Delete(ctx context.Context, id string) error
// Usage counts the takes and project segments that use the voice.
Usage(ctx context.Context, id string) (core.VoiceUsage, error)
// Links are the takes and segments that point at the voice, which
// Delete unlinks; Relink points them at it again (undoing a delete,
// after Put restored the profile), those linked elsewhere since left.
Links(ctx context.Context, id string) (VoiceLinks, error)
Relink(ctx context.Context, id string, l VoiceLinks) error
VoiceDir() string
}
Voices stores voice profiles; their blobs live in VoiceDir()/<id>/.
type WorkflowRecord ¶
type WorkflowRecord struct {
ID string
CreatedAt time.Time
UpdatedAt time.Time
Name string
Summary string // the steps, "Start → Speak → Export"
// State, Items and Done sum up the last run.
State string
Items int
Done int
// Doc is the workflow, Run its last run (nil before one); List
// leaves both nil.
Doc json.RawMessage
Run json.RawMessage
}
WorkflowRecord is a workflow as the store keeps it (M6): the documents the workflow service owns (internal/workflow.Workflow and its last Run as JSON; the store does not read them) and the columns lists show.
type Workflows ¶
type Workflows interface {
// PutDoc inserts or updates a workflow's document, name, summary and
// times, keeping its run.
PutDoc(ctx context.Context, r WorkflowRecord) error
// PutRun updates the run and its summary (State, Items, Done) of a
// saved workflow (core.ErrNotFound if there is none).
PutRun(ctx context.Context, r WorkflowRecord) error
Get(ctx context.Context, id string) (WorkflowRecord, error)
// List returns every workflow, most recently changed first, without
// documents.
List(ctx context.Context) ([]WorkflowRecord, error)
Delete(ctx context.Context, id string) error
// Dir is where the workflows' files live (<dir>/<id>/). Pure.
Dir() string
}
Workflows stores workflows. Like Dubs, it is not part of Store: sqlitestore.(*Store).Workflows returns it.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package historyjson reads the MVP's take library: WAVs in <dir>/clips and an index, <dir>/history.json.
|
Package historyjson reads the MVP's take library: WAVs in <dir>/clips and an index, <dir>/history.json. |
|
Package sqlitestore implements store.Store on SQLite, through the MyGo SQLite plugin (github.com/egoist/mygo/plugins/sqlite: purego, no cgo, FTS5 and JSON1 built in).
|
Package sqlitestore implements store.Store on SQLite, through the MyGo SQLite plugin (github.com/egoist/mygo/plugins/sqlite: purego, no cgo, FTS5 and JSON1 built in). |