types

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PubTypeUser               PubType = "user"
	PubTypeTranslation        PubType = "translation"
	PubTypeMissingTranslation PubType = "missingTranslation"
	PubTypeTranslationValue   PubType = "translationValue"
	PubTypeCategory           PubType = "category"
	PubTypeSnapshot           PubType = "snapshot"
	PubTypeLocale             PubType = "locale"
	PubTypeProject            PubType = "project"
	PubTypeOrganization       PubType = "organization"

	PubVerbCreate PubVerb = "create"
	PubVerbUpdate PubVerb = "update"
	// Marks the item as deleted in the database, but does not delete it
	PubVerbSoftDelete PubVerb = "soft-delete"
	// Removes all items permanently
	PubVerbClean       PubVerb = "clean"
	PubVerbConnectItem PubVerb = "connect"
)
View Source
const (
	// RootCategories are accessible without a key, but we do need a key.
	// A bit dirty.
	// Deprecated, will simply be an empty path
	RootCategory = ""
)

Variables

View Source
var DefaultLocales = []Locale{
	{
		IETF:      "en-GB",
		Iso639_1:  "en",
		Iso639_2:  "eng",
		Iso639_3:  "eng",
		Title:     "British",
		Fallbacks: []string{"eng", "en"},
	},
	{
		IETF:      "en-US",
		Iso639_1:  "en",
		Iso639_2:  "eng",
		Iso639_3:  "eng",
		Title:     "US English",
		Fallbacks: []string{"eng", "en"},
	},
	{
		IETF:      "nb-NO",
		Iso639_1:  "nb",
		Iso639_2:  "nob",
		Iso639_3:  "nob",
		Title:     "Norwegian bokmål",
		Fallbacks: []string{"nn-NO", "no", "dan", "swe", "eng"},
	},
	{
		IETF:      "nn-NO",
		Iso639_1:  "nn",
		Iso639_2:  "nno",
		Iso639_3:  "nno",
		Title:     "Norwegian Nynorsk",
		Fallbacks: []string{"nb-NO", "no", "dan", "swe", "eng"},
	},
}

TODO: build this data from som external api/resours For now, it is just a tiny sample of what I persionally am going to need now.

View Source
var (
	ErrNoLocales = errors.New("List of locales was empty")
)
View Source
var (
	Test_locales = Locales{
		{
			Entity:   Entity{ID: "loc-en"},
			Iso639_1: "en",
			Iso639_2: "en",
			Iso639_3: "eng",
			IETF:     "en-US",
		},
		{
			Entity:   Entity{ID: "loc-no"},
			Iso639_1: "no",
			Iso639_2: "no",
			Iso639_3: "nor",
			IETF:     "nb-NO",
		},
	}
)

Functions

func GetType added in v0.5.1

func GetType(v any) string

func SeedLocales

func SeedLocales(db localeSeeder, organizationID string, locales []Locale) error

Types

type Category

type Category struct {
	Entity
	Title          string   `json:"title"`
	Description    string   `json:"description,omitempty"`
	Key            string   `json:"key"`
	ProjectID      string   `json:"project_id,omitempty"`
	TranslationIDs []string `json:"translation_ids,omitempty"`
}

swagger:model Category

func (Category) AsUniqueFilter

func (cat Category) AsUniqueFilter() CategoryFilter

func (Category) Extend

func (c Category) Extend(db Storage, options ...ExtendOptions) (ec ExtendedCategory, err error)

func (Category) Filter

func (cat Category) Filter(f CategoryFilter) bool

Used to filter and search

func (Category) IsRoot

func (c Category) IsRoot() bool

func (Category) Keys

func (c Category) Keys() []string

Splits the key into multiple keys. Root-values are removed

func (Category) Kind

func (e Category) Kind() string

func (Category) Namespace

func (e Category) Namespace() string

func (Category) Path

func (cat Category) Path() []string

func (*Category) Update

func (cat *Category) Update(payload Category, options ...UpdateEntityOptions) error

type CategoryFilter

type CategoryFilter struct {
	OrganizationID string
	Key            string
	ID             string
	ProjectID      string
}

Used to filter and search along with Category.Filter(CategoryFilter)

type CategoryTreeNode

type CategoryTreeNode struct {
	ExtendedCategory
	Categories map[string]CategoryTreeNode `json:"categories,omitempty"`
}

func CreateCategoryTreeNode

func CreateCategoryTreeNode(extendedCategories map[string]ExtendedCategory) CategoryTreeNode

func (CategoryTreeNode) HasTranslationForLocaleDeep

func (node CategoryTreeNode) HasTranslationForLocaleDeep(localeID string) bool

type CreatorSource

type CreatorSource string
var (
	CreatorSourceUser       CreatorSource = "user"
	CreatorSourceTranslator CreatorSource = "system-translator"
	CreatorSourceImport     CreatorSource = "user-import"
)

type DatabaseBackup added in v0.8.4

type DatabaseBackup interface {
	Backup(w io.Writer) (int64, error)
}

type Entity

type Entity struct {
	// Time of which the entity was created in the database
	// Required: true
	CreatedAt time.Time `json:"created_at,omitempty"`
	// Time of which the entity was updated, if any
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
	// Unique identifier of the entity
	// Required: true
	ID string `json:"id,omitempty"`
	// User id refering to the user who created the item
	CreatedBy string `json:"created_by,omitempty"`
	// User id refering to who created the item
	UpdatedBy string `json:"updated_by,omitempty"`
	// If set, the item is considered deleted. The item will normally not get deleted from the database,
	// but it may if cleanup is required.
	Deleted *time.Time `json:"deleted,omitempty"`
	// Organizations are completely seperate from each-other.
	OrganizationID string `json:"-"`
}

func (Entity) IDString

func (e Entity) IDString() string

func (*Entity) Update

func (existing *Entity) Update(changes Entity, options ...UpdateEntityOptions) error

Updates an existing entity-struct with changes. NOTE: This does NOT update the db-value itself., but is meant as a helper-func

type ExtendOptions

type ExtendOptions struct {
	ByID, ByKeyLike  bool
	LocaleFilter     []string
	LocaleFilterFunc func(locale Locale) bool
	ErrOnNoLocales   bool
	IncludeDeleted   bool
}

func (ExtendOptions) Validate

func (o ExtendOptions) Validate() error

type ExtendedCategory

type ExtendedCategory struct {
	Category
	// TODO: change to map
	Exists       *bool                          `json:"exists,omitempty"`
	Translations map[string]ExtendedTranslation `json:"translations,omitempty"`
}

func (ExtendedCategory) HasTranslationForLocale

func (el ExtendedCategory) HasTranslationForLocale(localeID string) bool

type ExtendedLocale

type ExtendedLocale struct {
	Locale     `json:"locale"`
	Categories map[string]ExtendedCategory `json:"categories"`
}

type ExtendedProject

type ExtendedProject struct {
	Project      `json:"project"`
	Exists       *bool                       `json:"exists,omitempty"`
	Categories   map[string]ExtendedCategory `json:"categories" diff:"-"`
	CategoryTree CategoryTreeNode            `json:"category_tree"`
	Locales      map[string]Locale           `json:"locales"`
}

func (ExtendedProject) ByLocales

func (ep ExtendedProject) ByLocales() (map[string]ExtendedLocale, error)

func (ExtendedProject) CreateSnapshot

func (p ExtendedProject) CreateSnapshot(createdBy string) (s ProjectSnapshot, err error)

type ExtendedTranslation

type ExtendedTranslation struct {
	Translation `json:"translation"`
	Exists      *bool                       `json:"exists,omitempty"`
	Values      map[string]TranslationValue `json:"values"`
}

type KindReporter added in v0.5.1

type KindReporter interface {
	Kind() string
}

type Locale

type Locale struct {
	Entity
	// Represents the ISO-639-1 string, e.g. en
	Iso639_1 string `json:"iso_639_1"`
	// Represents the ISO-639-2 string, e.g. eng
	Iso639_2 string `json:"iso_639_2"`
	// Represents the ISO-639-3 string, e.g. eng
	Iso639_3 string `json:"iso_639_3"`
	// Represents the IETF language tag, e.g. en / en-US
	IETF  string `json:"ietf"`
	Title string `json:"title"`
	// List of other Locales in preferred order for fallbacks
	Fallbacks []string `json:"fallbacks,omitempty"`
}

# See https://en.wikipedia.org/wiki/Language_code for more information TODO: consider supporting other standards here, like Windows(?), which seem to have their own thing.

func (Locale) Kind

func (e Locale) Kind() string

func (Locale) Namespace

func (e Locale) Namespace() string

type LocaleSetting

type LocaleSetting struct {
	// If set, the locale will be visible for editing.
	Enabled bool `json:"enabled"`
	// If set, the associated translations will be published in releases.
	// This is useful for when adding new locales, and one don't want to publish it to users until it is complete
	Publish bool `json:"publish"`
	// If set, will allow registered translation-services to translate from other languages to this locale.
	// This might help speed up translations for new locales.
	// See the Config or Organization-settings for instructions on how to set up translation-services.
	//
	// * Organization-settings are not yet available.
	//
	// TODO: implement organization-settings
	AutoTranslation bool `json:"auto_translation"`
}

type Locales

type Locales []Locale

func (Locales) GetLocaleID

func (t Locales) GetLocaleID(key string) string

type LoginResponse

type LoginResponse struct {
	User
	Organization Organization `json:"organization"`
	Ok           bool         `json:"ok"`
	Expires      time.Time    `json:"expires"`
	ExpiresIn    string       `json:"expires_in"`
}

type MissingTranslation

type MissingTranslation struct {
	Entity
	ProjectID     string `json:"project_id"`
	CategoryID    string `json:"category_id"`
	TranslationID string `json:"translation_id"`
	LocaleID      string `json:"locale_id"`
	// The reported project (may not exist), as reported by the client.
	Project string `json:"project"`
	// The reported category (may not exist), as reported by the client.
	Category string `json:"category"`
	// The reported translation (may not exist), as reported by the client.
	Translation string `json:"translation"`
	// The reported locale (may not exist), as reported by the client.
	Locale string `json:"locale"`
	// Number of times it has been reported.
	Count int `json:"count"`

	FirstUserAgent  string `json:"first_user_agent"`
	LatestUserAgent string `json:"latest_user_agent"`
}

swagger:model MissingTranslation

type OrgStorage added in v0.8.0

type OrgStorage interface {
	GetOrganization(organizationID string) (*Organization, error)
	GetOrganizations() (map[string]Organization, error)
	CreateOrganization(organization Organization) (Organization, error)
	UpdateOrganization(id string, payload UpdateOrganizationPayload) (Organization, error)
	FindOrganizationByIdOrTitle(titleOrID string) (*Organization, error)
}

type Organization

type Organization struct {
	ID        string     `json:"id"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
	CreatedBy string     `json:"created_by"`
	UpdatedBy string     `json:"updated_by,omitempty"`
	Deleted   *time.Time `json:"deleted,omitempty"`

	Title       string `json:"title"`
	Description string `json:"description,omitempty"`
	// This will allow anybody with the id to create a standard user, and join the organization
	// The first user to join, gets priviliges to administer the organization.
	JoinID        string    `json:"join_id,omitempty"`
	JoinIDExpires time.Time `json:"join_id_expires"`
}

func SeedUsers

func SeedUsers(db userSeeder, users []User, pwHasher func(s string) ([]byte, error)) (*Organization, error)

Creates users and the initial organization.

func (Organization) IDString added in v0.8.0

func (e Organization) IDString() string

func (Organization) Kind added in v0.8.0

func (e Organization) Kind() string

func (Organization) Namespace added in v0.8.0

func (e Organization) Namespace() string

type Project

type Project struct {
	Entity
	ShortName    string                         `json:"short_name"`
	Title        string                         `json:"title"`
	Description  string                         `json:"description,omitempty"`
	IncludedTags []string                       `json:"included_tags,omitempty"`
	CategoryIDs  []string                       `json:"category_ids,omitempty"`
	LocaleIDs    map[string]LocaleSetting       `json:"locales,omitempty"`
	Snapshots    map[string]ProjectSnapshotMeta `json:"snapshots,omitempty" diff:"-"`
}

swagger:model Project

func (Project) Extend

func (p Project) Extend(db Storage, options ...ExtendOptions) (ep ExtendedProject, err error)

func (Project) Kind

func (e Project) Kind() string

func (Project) Namespace

func (e Project) Namespace() string

type ProjectSnapshot

type ProjectSnapshot struct {
	Entity      `json:"entity"`
	Project     ExtendedProject `json:"project"`
	ProjectHash uint64          `json:"project_hash"`
}

swagger:model ProjectSnapshot

func (ProjectSnapshot) Kind

func (e ProjectSnapshot) Kind() string

func (ProjectSnapshot) Namespace

func (e ProjectSnapshot) Namespace() string

type ProjectSnapshotMeta

type ProjectSnapshotMeta struct {
	Description string       `json:"description"`
	CreatedAt   time.Time    `json:"created_at"`
	CreatedBy   string       `json:"created_by"`
	SnapshotID  string       `json:"id"`
	Hash        uint64       `json:"hash"`
	UploadMeta  []UploadMeta `json:"uploadMeta"`
}

type PubType

type PubType string

type PubVerb

type PubVerb string

type ReleaseInfo

type ReleaseInfo struct {
	URL             string `json:"url"`
	AssetsURL       string `json:"assets_url"`
	UploadURL       string `json:"upload_url"`
	HTMLURL         string `json:"html_url"`
	TagName         string `json:"tag_name"`
	TargetCommitish string `json:"target_commitish"`
	Name            string `json:"name"`
	Draft           bool   `json:"draft"`
	Prerelease      bool   `json:"prerelease"`
	CreatedAt       string `json:"created_at"`
	PublishedAt     string `json:"published_at"`
	Body            string `json:"body"`
}

func GetLatestVersion

func GetLatestVersion(url string, c *http.Client) (*ReleaseInfo, error)

type ServerInfo

type ServerInfo struct {
	// When the server was started
	ServerStartedAt time.Time `json:"server_started_at"`
	// Short githash for current commit
	GitHash string `json:"git_hash"`
	// Version-number for commit
	Version string `json:"version"`
	// Date of build
	BuildDate time.Time `json:"build_date"`

	// Server-instance. This will change on every restart.
	Instance string `json:"instance"`
	// Hash of the current host. Should be semi-stable
	HostHash string `json:"host_hash"`

	// Size of database.
	DatabaseSize     int64        `json:"database_size"`
	DatabaseSizeStr  string       `json:"database_size_str"`
	LatestRelease    *ReleaseInfo `json:"latest_release"`
	LatestReleaseCLI *ReleaseInfo `json:"latest_cli_release"`
	// The minimum version of skiver-cli that can be used with this server.
	// The is [semver](https://semver.org/)-compatible, but has a leading `v`, like `v1.2.3`
	CliVersionConstraints string `json:"cli_version_contraints,omitempty"`
}

type Session

type Session struct {
	Token        string
	User         User
	Organization Organization
	UserAgent    string
	Issued       time.Time
	Expires      time.Time
}

type State

type State struct {
	MigrationPoint int
}

type Storage

type Storage interface {
	UserStorage
	OrgStorage
	Size() (int64, error)

	GetState() (*State, error)
	SetState(newState State) (State, error)

	GetLocale(ID string) (Locale, error)
	CreateLocale(locale Locale) (Locale, error)
	GetLocaleFilter(filter ...Locale) (*Locale, error)
	GetLocales() (map[string]Locale, error)
	GetLocaleByIDOrShortName(shortNameOrId string) (*Locale, error)

	GetProject(ID string) (*Project, error)
	CreateProject(project Project) (Project, error)
	UpdateProject(id string, project Project) (Project, error)
	GetProjects() (map[string]Project, error)
	GetProjectByIDOrShortName(shortNameOrId string) (*Project, error)
	FindProjects(max int, filter ...Project) (map[string]Project, error)

	GetTranslation(ID string) (*Translation, error)
	SoftDeleteTranslation(id string, byUser string, deleteDate *time.Time) (Translation, error)
	CreateTranslation(locale Translation) (Translation, error)
	GetTranslations() (map[string]Translation, error)
	GetTranslationsFilter(max int, filter ...Translation) (map[string]Translation, error)
	UpdateTranslation(id string, paylaod Translation) (Translation, error)

	// These must be added
	GetCategory(ID string) (*Category, error)
	CreateCategory(category Category) (Category, error)
	GetCategories() (map[string]Category, error)
	UpdateCategory(id string, category Category) (Category, error)
	FindCategories(max int, filter ...CategoryFilter) (map[string]Category, error)

	GetTranslationValue(ID string) (*TranslationValue, error)
	CreateTranslationValue(translationValue TranslationValue) (TranslationValue, error)
	// TODO: this should take in a id as first parameter
	UpdateTranslationValue(tv TranslationValue) (TranslationValue, error)
	GetTranslationValues() (map[string]TranslationValue, error)
	GetTranslationValueFilter(filter ...TranslationValue) (*TranslationValue, error)
	GetTranslationValuesFilter(max int, filter ...TranslationValue) (map[string]TranslationValue, error)

	ReportMissing(key MissingTranslation) (*MissingTranslation, error)
	GetMissingKeysFilter(max int, filter ...MissingTranslation) (map[string]MissingTranslation, error)
	UpdateUser(id string, payload UpdateUserPayload) (User, error)

	GetSnapshot(snapshotId string) (*ProjectSnapshot, error)
	FindSnapshots(max int, filter ...ProjectSnapshot) (map[string]ProjectSnapshot, error)
	CreateSnapshot(snapshot ProjectSnapshot) (ProjectSnapshot, error)
	FindOneSnapshot(filter ...ProjectSnapshot) (*ProjectSnapshot, error)
}

type Translation

type Translation struct {
	Entity
	Aliases             []string               `json:"aliases,omitempty"`
	ParentTranslationID string                 `json:"parent_translation,omitempty"`
	Description         string                 `json:"description,omitempty"`
	Key                 string                 `json:"key,omitempty"`
	CategoryID          string                 `json:"category,omitempty"`
	Tag                 []string               `json:"tags,omitempty"`
	Title               string                 `json:"title,omitempty"`
	Variables           map[string]interface{} `json:"variables,omitempty"`
	References          []string               `json:"references,omitempty"`
	ValueIDs            []string               `json:"value_ids,omitempty"`
}

swagger:model Translation

func (Translation) Extend

func (t Translation) Extend(db Storage, options ...ExtendOptions) (et ExtendedTranslation, err error)

func (Translation) GetProject

func (e Translation) GetProject(db Storage) (Project, error)

func (Translation) Kind

func (e Translation) Kind() string

func (Translation) Namespace

func (e Translation) Namespace() string

type TranslationValue

type TranslationValue struct {
	Entity
	// The pre-interpolated value to use  with translations
	// Example: The {{productName}} fires up to {{count}} bullets of {{subject}}.
	Value string `json:"value,omitempty"`
	// locale ID
	LocaleID string `json:"locale_id,omitempty"`
	// Translation ID
	TranslationID string `json:"translation_id,omitempty"`
	// Indicating from where the value was created from, usually user, but could be a tranlator-service, like Bing.
	Source  CreatorSource     `json:"source,omitempty"`
	Context map[string]string `json:"context,omitempty"`
}

swagger:model TranslationValue

func (TranslationValue) Kind

func (e TranslationValue) Kind() string

func (TranslationValue) Namespace

func (e TranslationValue) Namespace() string

type UpdateEntityOptions

type UpdateEntityOptions struct {
	IgnoreMissingFields   bool
	SkipUpdatingUpdatedAt bool
}

type UpdateOrganizationPayload added in v0.8.0

type UpdateOrganizationPayload struct {
	UpdatedBy     string
	JoinID        *string
	JoinIDExpires *time.Time
}

type UpdateUserPayload added in v0.8.0

type UpdateUserPayload struct {
	UserName          *string
	PW                *[]byte
	TemporaryPassword *bool
	Entity
}

func (*UpdateUserPayload) SetTemporaryPassword added in v0.8.0

func (p *UpdateUserPayload) SetTemporaryPassword(temp bool) *UpdateUserPayload

func (*UpdateUserPayload) SetUpdatedBy added in v0.8.0

func (p *UpdateUserPayload) SetUpdatedBy(userid string) *UpdateUserPayload

func (*UpdateUserPayload) SetUserName added in v0.8.0

func (p *UpdateUserPayload) SetUserName(s string) *UpdateUserPayload

type UploadMeta added in v0.8.0

type UploadMeta struct {
	ID           string `json:"id"`
	Locale       string `json:"locale"`
	LocaleKey    string `json:"locale_key"`
	Parent       string `json:"parent"`
	Tag          string `json:"tag"`
	ProviderID   string `json:"provider_id"`
	ProviderName string `json:"provider_name"`
	URL          string `json:"url"`
	Size         int64  `json:"size"`
}

type User

type User struct {
	Entity   `json:"entity"`
	UserName string `json:"username"`
	// If not active, the account cannot be used until any issues are resolved.
	Active bool      `json:"active"`
	Store  UserStore `json:"-"`
	// If set, the user must change the password before the account can be used
	TemporaryPassword bool   `json:"temporary_password,omitempty"`
	PW                []byte `json:"-"`

	CanCreateOrganization bool `json:"can_create_organization,omitempty"`
	CanCreateUsers        bool `json:"can_create_users,omitempty"`
	CanCreateProjects     bool `json:"can_create_projects,omitempty"`
	CanCreateTranslations bool `json:"can_create_translations,omitempty"`
	CanCreateLocales      bool `json:"can_create_locales,omitempty"`

	CanUpdateOrganization bool `json:"can_update_organization,omitempty"`
	CanUpdateUsers        bool `json:"can_update_users,omitempty"`
	CanUpdateProjects     bool `json:"can_update_projects,omitempty"`
	CanManageSnapshots    bool `json:"can_manage_snapshots,omitempty"`
	CanUpdateTranslations bool `json:"can_update_translations,omitempty"`
	CanUpdateLocales      bool `json:"can_update_locales,omitempty"`
}

swagger:model User

func (User) Kind

func (e User) Kind() string

func (User) Namespace

func (e User) Namespace() string

type UserSessionOptions

type UserSessionOptions struct {
	TTL time.Duration
}

type UserStorage

type UserStorage interface {
	GetUser(userId string) (*User, error)
	FindUsers(max int, filter ...User) (map[string]User, error)
	FindUserByUserName(organizationID, userName string) (*User, error)
	CreateUser(user User) (User, error)
}

type UserStore

type UserStore int
const (
	// A local user, with password stored in the database.
	UserStoreLocal UserStore = iota + 1
)

Jump to

Keyboard shortcuts

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