Documentation
¶
Overview ¶
Package formavailability serves the live check behind a name field: a person types the name of something they are ordering — a SharePoint site, a Microsoft 365 group — and the form says at once whether that name is still free (ADR-0519).
It is ADR-0473's ephemeral worker query asked a narrower question. A directory field searches and offers a page; an availability field asks one value lookup per source the field names and learns one bit from each: is there something under this name. The answer the browser receives is that bit, folded over every source, and nothing else — no id, no display name, nothing about what holds the name.
**What the request may say** is the value typed and nothing more. Which Worker, which tenant, which resource, which SharePoint host and managed path — all of that is read from the stored form and checked against the provider table below, at save and again here, and a request naming any of it is refused.
**The check is a courtesy, not the rule.** Two people can be told the same name is free a second apart, and a name can be taken between the order and its provisioning. The process that creates the object asks again and owns the refusal; this check only spares a person an order that was going to come back.
**This area owns no state** (I3): its collaborators are the server's, a query waits on the request's own goroutine, and nothing here reaches the log, the processor or recovery.
Index ¶
Constants ¶
const DefaultTimeout = 8 * time.Second
DefaultTimeout is what a person waits for at most. The checks run side by side, so a field with three sources waits as long as its slowest one.
const Member = "atlasAvailability"
Member is the component member that makes a textfield an availability field.
const Version = 1
Version is the one version of the block this server reads.
Variables ¶
var Codes = []string{
"not_found", "invalid_query", "invalid_value", "invalid_configuration", "forbidden", "rate_limited",
"worker_unavailable", "worker_busy", "provider_throttled", "provider_unavailable", "provider_refused", "timeout",
}
Codes are the machine-readable codes a check answers with beside its message.
var FieldTypes = []string{"textfield"}
FieldTypes are the form-js fields an availability field may be: the one that holds a typed name.
Functions ¶
func CheckSchema ¶
CheckSchema is the save-time check: a form whose availability blocks this server could not serve is refused with the reason, rather than saved and failing when somebody types.
Types ¶
type Answer ¶
Answer is what a check answers: the value as it was checked, and whether every source the field names reports it free.
type Check ¶
type Check struct {
WorkerType string `json:"workerType"`
Worker string `json:"worker"`
Resource string `json:"resource"`
// Host and ManagedPath locate a SharePoint site: https://<host>/<managedPath>/<name>.
Host string `json:"host,omitempty"`
ManagedPath string `json:"managedPath,omitempty"`
}
Check is one source as a block names it.
type Config ¶
type Config struct {
// Worker resolves a Worker by name from the Worker store.
Worker func(name string) (Worker, bool, error)
// Ask puts a query to a Worker Instance and waits for its answer.
Ask func(ctx context.Context, jobType, connector string, q lookup.Query, timeout time.Duration) (lookup.Page, error)
// Allow is the per-person rate limit.
Allow func(key string) bool
// Principal names the caller, for the rate limit. Empty when the server runs
// without authentication.
Principal func(r *http.Request) string
// Timeout bounds one query.
Timeout time.Duration
// MaxBody bounds a request's body.
MaxBody int64
}
Config is the server's half of this area.
type Form ¶
Form is the availability fields of one form, by key.
type Provider ¶
type Provider struct {
WorkerType string `json:"workerType"`
Resource string `json:"resource"`
// JobType routes the query to Worker Instances serving this Worker Type.
JobType string `json:"-"`
// Label names the source to a model author.
Label string `json:"label"`
// Property is what the source returns about a record that holds the name; it is
// asked for so the Worker has something to project, and never passed on.
Property string `json:"-"`
// Located marks a source that needs a host — SharePoint, whose sites are addressed
// under the tenant's host and a managed path.
Located bool `json:"located,omitempty"`
// ValueFormat says in words what a value must look like, for an error message.
ValueFormat string `json:"valueFormat"`
// contains filtered or unexported fields
}
Provider is one source a field may ask: a resource of a Worker Type, answered by a value lookup.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service answers availability checks. Build it with New.
func (*Service) WriteCheck ¶
func (s *Service) WriteCheck(w http.ResponseWriter, r *http.Request, schema []byte, fieldKey string)
WriteCheck answers a check of one field of a stored form, read by the caller from wherever the form is reached — a form id, a task. The request names only the value.
type Source ¶
type Source struct {
Version int `json:"version"`
Checks []Check `json:"checks"`
// MinLength is how many characters a value needs before it is checked. Absent
// means 3.
MinLength *int `json:"minLength,omitempty"`
}
Source is the atlasAvailability block as a form states it.
type Worker ¶
type Worker struct {
WorkerType string
Enabled bool
// FormLookups is the Worker's own switch (ADR-0473): its editors decide whether a
// form may ask anything through its credential. An availability check asks less
// than a directory search, but through the same credential, so it needs the same
// consent.
FormLookups bool
}
Worker is a configured Worker as this area judges it: no endpoint and nowhere to put a credential.