Documentation
¶
Overview ¶
Package schemas owns the JSON Schemas that back tap's editor modelines.
Every YAML document tap hands to $EDITOR — and every config file it persists — carries a `# yaml-language-server: $schema=<uri>` modeline so a language server can offer completion, hover, and validation. Pointing that modeline at the published GitHub URL means the editor resolves whatever is on main, which is the wrong answer for anyone running a build that is ahead of (or behind) main, and no answer at all offline.
Instead the schemas are embedded in the binary and materialized under the user's data dir on demand. The modeline then points at a file:// URI whose contents are guaranteed to match the binary that wrote it. Materialization compares content rather than versions, so a schema edit is picked up by the next command that writes a modeline.
The published URLs remain the canonical $id values inside the schema files, and are the fallback whenever materialization is not possible.
Index ¶
- Constants
- func Dir(rt *toolkit.Runtime) (string, error)
- func EnsureModeline(data []byte, modeline string) []byte
- func FileURI(path string) string
- func HasModeline(data []byte) bool
- func Materialize(rt *toolkit.Runtime) (string, error)
- func Modeline(rt *toolkit.Runtime, name string) string
- func ModelineURI(rt *toolkit.Runtime, name string) string
- func Names() []string
- func PublicURL(name string) string
- func Read(name string) ([]byte, error)
- func ReplaceModeline(data []byte, modeline string) []byte
- func StripModeline(data []byte) []byte
Constants ¶
const ( TapConfig = "tap-config.json" FlightManifest = "flight-manifest.json" KegSettings = "keg-settings.json" KegSchemaDefinition = "keg-schema-definition.json" )
Schema file names, as they appear both in the embedded FS and on disk.
const ( TapConfigURL = publicBase + TapConfig FlightManifestURL = publicBase + FlightManifest KegSettingsURL = publicBase + KegSettings KegSchemaDefinitionURL = publicBase + KegSchemaDefinition )
Published URLs for each schema. Exported so pkg/tapper and pkg/keg can keep their long-standing *SchemaURL constants pointing at a single definition.
const ModelinePrefix = "# yaml-language-server: $schema="
ModelinePrefix is the literal yaml-language-server directive. A modeline is this prefix followed by a schema URI, alone on its own line.
Variables ¶
This section is empty.
Functions ¶
func Dir ¶
Dir returns the directory the embedded schemas are materialized into: <user data dir>/tapper/schemas. Resolution flows through the runtime, so a sandboxed test gets its own directory rather than the developer's.
func EnsureModeline ¶
EnsureModeline prepends modeline to data unless data already carries one.
func FileURI ¶
FileURI converts an absolute filesystem path to a file:// URI. Windows paths gain the extra leading slash (file:///C:/...) and forward slashes.
func HasModeline ¶
HasModeline reports whether data already carries a schema modeline in its leading comment block. Only the comments before the first content line are considered — a `# yaml-language-server:` string further down is data, not a directive.
func Materialize ¶
Materialize writes every embedded schema whose on-disk copy is missing or differs, and returns the directory holding them. Comparing content rather than a version stamp keeps it correct across development builds, where the version does not move but the schema does.
func ModelineURI ¶
ModelineURI returns the URI a modeline for name should point at: a file:// URI for the materialized copy, or the published URL when the schemas cannot be written (a read-only data dir, a constrained sandbox). It never fails — a stale modeline is a worse outcome than a remote one, and both are only comments.
func ReplaceModeline ¶
ReplaceModeline swaps whatever schema modeline data carries for modeline, prepending it when there is none. This is the choke point every write path runs its serialized YAML through: the serializers emit the published URL as a stable default, and the write path rewrites it to the local copy.
func StripModeline ¶
StripModeline removes the schema modeline from data's leading comment block, leaving everything else byte-for-byte. Documents that are stored rather than merely displayed run through this on the way in, so the modeline stays an editor affordance instead of becoming content: it names a path that is only meaningful on the machine that opened the editor.
Types ¶
This section is empty.