Skip to main content

Platform libraries

Turn ships some Lua code with the platform itself, so apps that need the same thing don't each carry their own copy. A platform library is available to every Lua app without being added to its ZIP: the app requires it the same way it requires its own modules.

Copies drift: a fix made in one copy never reaches the others, and two apps writing to one FHIR server with their own client code can disagree about which Patient a contact is. A library has one implementation, and a fix to it reaches every app when the platform deploys.

Libraries​

LibraryWhat it is for
turn.healthpass.dsThe design system behind patient-facing pages: cards, buttons, badges, a drawer, a PIN input, icons and illustrations. See the components.
turn.healthpass.fhirThe FHIR R4 machinery apps share: the store adapter, opening a connection, finding a contact's Patient, documents, and clinical resources.

Using a library​

A library is laid out like an app, and an app reaches each part with the calls it already uses for its own files:

PartWhere it livesHow an app uses it
Lua modulesturn/<family>/<library>/require("turn.healthpass.ds.components.buttons")
Liquid templatesassets/liquid/turn/<family>/<library>/turn.liquid.render("turn/healthpass/ds/badge", vars)
Static filesassets/public/turn/<family>/<library>/turn.assets.load("public/turn/healthpass/ds/icons/eye.svg"), or the versioned_static_url filter in a template

Every path in a library starts with turn/<family>/<library>/, in all three places, so a library can't collide with an app's own files or with another library.

Which file wins​

The app is asked first. When an app's ZIP carries a file at the same path as a library file, the app's copy is used and the library's is not. That is how an app pins a version it depends on, at the cost of no longer getting the library's fixes for that file.

Versions​

There is one version of each library: the one in the running platform release. Every app that relies on a library gets a change to it when the platform deploys, with no action on the app's side.

So a library changes in ways existing apps can absorb. A change that would break existing callers ships under a new name, next to the old one, and apps move across when they are ready.

Testing​

On a number, the platform serves the libraries to your app. The Turn Lua SDK doesn't include them yet, so a spec that requires a platform library can't load it on your machine. Until it does, test the code that uses a library on a number, or stand in for the library in your specs by putting your own module in package.loaded under the library's name before the code under test requires it.