metacore Start a pilot

Developers · Interfaces

Typed SDKs, generated from the API.

An SDK is generated whole from the public API, so a new operation reaches every SDK at its next build. From your schema, the CLI also writes typed code for your domain.

Terminal
$ metacore schema sdk go --file configuration.txtpb \
    --go-import example.com/domains
configuration/configuration.go
configurationclient/configurationclient.go
configuration/configuration.go
// SettingMode is a value that the field mode of setting allows.
type SettingMode string

// The values that mode allows.
const (
	SettingModeOff    SettingMode = "off"
	SettingModeShadow SettingMode = "shadow"
	SettingModeOn     SettingMode = "on"
)

Typed code

A renamed field is a compiler error.

Write the typed code of your domain again after each deployment. A field that the schema renames or retypes then fails your build, not a call at run time.

From your schemaThe CLI writes
TypesA type for each entity, key and field.
ValuesA name for each value that a field allows.
Change setsThe change sets of each layer.
SearchConditions and sorts for a search.
AtomsAtoms with typed inputs and answers.
ClientsA client for each entity.

Typed from your schema

The code above is part of what the command writes for the schema of one setting.

main.go
key := configuration.SettingKey{
	Name: "export.batch",
}
support := &apiv1.ScopeValue{
	Scope: "team", Value: "support",
}

changes := &configuration.Changes{}
changes.Setting(key, support).
	ExpectLimit(200).
	SetLimit(500).
	SetMode(configuration.SettingModeShadow)

client := configurationclient.Of(domain)
answer, err := client.Submit(ctx, changes)

Your code, on the typed SDK

One change of one setting, for the support team. It expects the limit that it read: of two runs that expect one value and change it, one publishes.

Client

The client does the careful parts.

An SDK is a client of the public API like any other. It holds no code of the platform, and no operation that another client lacks.

The clientWhat it does
Call keysA change made with no call key gets a new one, which every attempt keeps.
RetriesIt sends a call again only where that is safe: a read, or a change with its call key.
PagesA list is pages to iterate. A page is read only when your code comes to it.
Long workIt follows a run, a job or an export until it ends, or waits for a person.
Event streamIt follows a stream past the end of each minute, with its cursor.

What you do not write

A change that got no answer at any attempt says so, with its call key: send it again within a day.

An SDKWhat it means
CompleteGenerated whole from the public API. No operation is missing, and none is written by hand.
Read your writesThe client carries the position of each answer by itself.
Sign-inAs an app with its key, or for a person through OAuth with PKCE.
RefusalsAn error with its code, its reason and its field, so your code acts on the reason.
AtomsIt holds the server of your atoms too.

What every SDK gives

More SDKs follow the same contract.

Drift

It knows the schema it was written from.

The typed SDK keeps the digest of its schema. Write it from a file, or from a domain’s live schema, and check at start that the two still agree.

Terminal
$ metacore schema sdk go -e production \
    -d configuration --go-import example.com/domains
main.go
digest, same, err := client.CheckSchema(ctx)
if err == nil && !same {
	log.Printf("configuration runs %s", digest)
}

From the live schema

The command reads the domain’s live schema, and that of each domain that it depends on.

WhenWhat happens
A field is renamedThe engine still takes its former name, until a later deployment drops it.
You write it againCode that names the former field fails your build.
A type differsA value of another type is an error that names its field, never a guess.
The digest differsThe typed SDK tells that the live schema is another one.

When the schema changes

A typed read never calls once for each reference: it reads the records that a page refers to at once.

See also

Build your domain.

Declare its schema, and take it to production, self-hosted or in a managed region.

Briefing