Dextrin.Schema.FileResolver (Dextrin v0.3.3)

Copy Markdown View Source

A struct_resolver finding a struct's schema in .dxns files on disk, by the convention DXNS.md §6 states for every implementation -- so one set of schema files serves them all. Swappable like any resolver (Dextrin.Registry.put_resolver/2): anyone with another convention writes their own.

The convention. A name is segments joined by ., with at most one / between a namespace and a name (Foo.Bar/Baz); every segment is a directory but the last, which names the file. A schema of version N named Foo.Bar/Baz is looked for, on each search path in order, in

layoutversion 1version N
directoriesFoo/Bar/Baz.dxns, Foo/Bar/Baz-v1.dxnsFoo/Bar/Baz-vN.dxns
a directory per nameFoo/Bar/Baz/v1.dxnsFoo/Bar/Baz/vN.dxns
flatFoo.Bar.Baz.dxns, Foo.Bar.Baz-v1.dxnsFoo.Bar.Baz-vN.dxns
the namespace filethe entry Baz in Foo.Bar.dxnsthe same, by its %schema(N)

and a name with no / is its own namespace: Money in Money.dxns.

  • The first search path that has the name at all decides.
  • A file's version is its schema's: Baz-v2.dxns holds Baz as %schema(2), or is refused (schema/compile).
  • One version is found once: two files holding the same version are refused, naming both, rather than one being picked.
  • Every version found is loaded, so that a struct written with an older one reaches the materializer.

Summary

Functions

A struct_resolver searching search_paths in order.

Functions

for_paths(search_paths)

@spec for_paths([Path.t()]) :: Dextrin.Registry.struct_resolver()

A struct_resolver searching search_paths in order.