sysmlapi

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sysmlapi drives any server speaking the standard SysML v2 API: the projects, branches, commits and elements resources the OMG pilot's SysML-v2-API-Services and Flexo MMS alike serve. It knows nothing of a server's extras — Flexo's Layer 1, orgs and Turtle graph writes live in package flexo, which builds on this client.

Index

Constants

View Source
const (
	EnvBaseURL   = "FLEXO_SYSMLV2_URL"
	EnvToken     = "FLEXO_INTEROP_TOKEN" // #nosec G101 -- a variable name, not a credential
	EnvPlainHTTP = "FLEXO_ALLOW_PLAIN_HTTP"
)

Environment variables a client is configured from. The base URL and the token are the ones `sysml -sync` reads, so a REPL and the command line address one server the same way; the token is optional, as the pilot's server takes none.

View Source
const DefaultBaseURL = "http://localhost:8083"

DefaultBaseURL is the SysML v2 API port of flexo-mms-sysmlv2's compose file.

View Source
const DefaultTimeout = 60 * time.Second

DefaultTimeout bounds one request when the configuration names none.

Variables

View Source
var ErrUntyped = errors.New("the element has no single SysML metaclass")

ErrUntyped is an element with no single sysml: metaclass, which the API's payload cannot state.

Functions

func CheckURL

func CheckURL(raw string) error

CheckURL refuses a plaintext URL to anything but a loopback host, unless the environment opts in with FLEXO_ALLOW_PLAIN_HTTP=1, and any URL that is not http(s).

func CommitRequest

func CommitRequest(changes []reposync.ElementChange, message string) ([]byte, error)

CommitRequest encodes a batch of element changes as the API's CommitRequest: creates and updates send the element whole under its identity, deletes send a null payload.

func ElementsGraph

func ElementsGraph(elements []Element) (*rdf.Graph, error)

ElementsGraph reads a commit's elements as the RDF graph their API JSON spells, the inverse of what a commit's payloads were written from.

func Loopback

func Loopback(host string) bool

Loopback reports a host name that resolves to this machine without a lookup.

func Status

func Status(err error) int

Status returns the HTTP status of a failed request, or 0 if err is not one.

Types

type Branch

type Branch struct {
	ID   string `json:"@id"`
	Name string `json:"name"`
	Head Commit `json:"head"`
}

Branch is one branch as the API describes it: its id, its name and the commit at its head.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to one server. It is safe for sequential use.

func New

func New(cfg Config) *Client

New returns a client for cfg.

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL is the server's base path.

func (*Client) Branch

func (c *Client) Branch(ctx context.Context, project, branch string) (Branch, error)

Branch reads one branch of a project, head commit included.

func (*Client) Branches

func (c *Client) Branches(ctx context.Context, project string) ([]Branch, error)

Branches lists every branch of a project, paged through to the end.

func (*Client) Commits

func (c *Client) Commits(ctx context.Context, project string) ([]Commit, error)

Commits lists a project's commits, in the order the server returns them.

func (*Client) Config

func (c *Client) Config() Config

Config returns the configuration the client was built with.

func (*Client) CreateProject

func (c *Client) CreateProject(ctx context.Context, id, name, branch string) (Project, error)

CreateProject creates a project. An id names the project when the server honours client ids, as Flexo does; a default branch names the branch the server creates with it. Either empty leaves the choice to the server.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, target string, body []byte, contentType string, headers map[string]string) ([]byte, http.Header, error)

Do performs one request, authorized when the configuration holds a token, and returns the response body and headers, failing on any status outside 2xx.

func (*Client) ElementByID

func (c *Client) ElementByID(ctx context.Context, project, commit, id string) (Element, error)

ElementByID reads one element directly. A non-2xx answer is returned as the error, with Status(err) carrying the code.

func (*Client) Elements

func (c *Client) Elements(ctx context.Context, project, commit string, size int) (Listing, error)

Elements reads a commit's elements a page at a time. A page that overruns size or repeats an element is a server ignoring paging; the repeat is dropped rather than counted twice.

func (*Client) PostChanges

func (c *Client) PostChanges(ctx context.Context, project, branch string, changes []byte) (Commit, error)

PostChanges commits a CommitRequest body through the server's commit path and returns the commit it made. An empty branch takes the default one.

func (*Client) Project

func (c *Client) Project(ctx context.Context, id string) (Project, error)

Project reads one project by id.

func (*Client) Projects

func (c *Client) Projects(ctx context.Context) ([]Project, error)

Projects lists every project, paged through to the end.

func (*Client) Reachable

func (c *Client) Reachable(ctx context.Context) error

Reachable reports whether the server answers: the project list is the cheapest read every server has.

func (*Client) Repository

func (c *Client) Repository(project, branch string) *Repository

Repository addresses one project branch for a sync.

func (*Client) Roots

func (c *Client) Roots(ctx context.Context, project, commit string) ([]Element, error)

Roots lists the elements the server considers roots of a commit: those with neither an owner nor an owning related element.

type Commit

type Commit struct {
	ID   string `json:"@id"`
	Type string `json:"@type"`
}

Commit identifies one commit of a project.

type Config

type Config struct {
	BaseURL string        // the API's base path, without a trailing slash
	Token   string        // bearer token, sent only when set
	Timeout time.Duration // per-request bound; DefaultTimeout when zero
}

Config addresses one SysML v2 API server.

func ConfigFromEnv

func ConfigFromEnv() Config

ConfigFromEnv reads the base URL and the token from the environment; the URL defaults to the compose file's port, the token to none.

type Element

type Element map[string]json.RawMessage

Element is one element as the API delivers it: property name to raw JSON value, kept raw so a value's shape — reference, literal, array — is observable rather than normalized away by decoding into a Go type.

func (Element) ID

func (e Element) ID() string

ID returns an element's identity, preferring @id over elementId.

func (Element) Type

func (e Element) Type() string

Type returns an element's @type, or "" when it carries none.

type Listing

type Listing struct {
	Elements      []Element
	Responses     int
	IgnoredPaging bool
}

Listing is one element listing: the elements it delivered, the number of responses it took, and whether the server ignored the paging parameters.

type PlaintextError

type PlaintextError struct {
	URL string
}

PlaintextError is a bearer token about to cross the network unencrypted: an http:// URL whose host is not this machine.

func (*PlaintextError) Error

func (e *PlaintextError) Error() string

type Project

type Project struct {
	ID            string `json:"@id"`
	Name          string `json:"name"`
	DefaultBranch Ref    `json:"defaultBranch"`
}

Project is one project as the API describes it.

type Ref

type Ref struct {
	ID string `json:"@id"`
}

Ref is a reference to another resource, as the API spells it.

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

Repository is one project branch as a sync's repository: read as the graph its elements spell, written through the commit path so every element keeps its id. It remembers the head its last read stood at — empty for a branch read before its first commit — and refuses to commit past a head that has since moved.

func (*Repository) Branch

func (r *Repository) Branch() string

Branch is the id of the branch the repository reads and writes.

func (*Repository) Client

func (r *Repository) Client() *Client

Client is the client the repository reads and writes through.

func (*Repository) Commit

func (r *Repository) Commit(ctx context.Context, changes []reposync.ElementChange, message string) (string, error)

Commit writes one batch as one SysML v2 commit. The API takes no precondition, so once a head is known — read by Graph, resumed or written — it is re-read first and a moved one refuses the write as a StaleBranchError; a branch read without a head has to be still without one.

func (*Repository) Graph

func (r *Repository) Graph(ctx context.Context) (*rdf.Graph, error)

Graph reads the branch as its head commit left it, so the read is of one commit rather than of a branch that may move under it. A branch with no commit yet reads as an empty graph.

func (*Repository) GraphAt

func (r *Repository) GraphAt(ctx context.Context, commit string) (*rdf.Graph, error)

GraphAt reads the branch as one commit left it: its elements, paged through and read as the graph their JSON spells.

func (*Repository) Head

func (r *Repository) Head(ctx context.Context) (string, error)

Head is the branch's current head commit; empty for a branch no commit has reached yet, as a freshly created project's is on some servers.

func (*Repository) Project

func (r *Repository) Project() string

Project is the id of the project the repository is a branch of.

func (*Repository) Resume

func (r *Repository) Resume(commit string)

Resume records the last-seen commit a saved sync state carries, so a head that has since moved is refused instead of written past.

func (*Repository) Seen

func (r *Repository) Seen() string

Seen is the head commit the last Graph read stood at, or the last commit this repository wrote; empty before either.

type Representation

type Representation struct{}

Representation is what the server stores of a posted graph: sysml: properties only, values as JSON spells them. A diff under it converges with an apply.

func (Representation) Carry

func (Representation) Carry(triple rdf.Triple) (rdf.Triple, bool, error)

Carry keeps sysml: properties in the form the server stores them and drops every other predicate: it has no place for them.

type StaleBranchError

type StaleBranchError struct {
	Project, Branch, Seen, Head string
}

StaleBranchError is a branch whose head moved between the read a change set was computed against and the commit that would have written it; nothing was written, and the change set has to be recomputed against the new head.

func (*StaleBranchError) Error

func (e *StaleBranchError) Error() string

type StatusError

type StatusError struct {
	Method string
	URL    string
	Status int
	Body   string
}

StatusError is a response outside 2xx. It carries the body, because servers answer with their diagnostic there.

func (*StatusError) Error

func (e *StatusError) Error() string

func (*StatusError) Message

func (e *StatusError) Message() string

Message is the server's diagnostic: the body's message field when it is a JSON object stating one, else the body itself, trimmed to a line's worth.

type UnreachableError

type UnreachableError struct {
	URL string
	Err error
}

UnreachableError is a server that answered nothing: the connection failed before any status came back.

func (*UnreachableError) Error

func (e *UnreachableError) Error() string

func (*UnreachableError) Unwrap

func (e *UnreachableError) Unwrap() error

type UnrepresentableError

type UnrepresentableError struct {
	Term   rdf.Term
	Reason string
}

UnrepresentableError is a value the server's JSON commit path has no spelling for; the diff refuses it rather than approximating.

func (*UnrepresentableError) Error

func (e *UnrepresentableError) Error() string

Jump to

Keyboard shortcuts

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