MultiPaaS

The model

The model is your description of the data your application keeps. It is made of entities, fields, enums and constraints. MultiPaaS builds the generated API from it.

Entities and fields

An entity is a kind of record, such as a Recipe or a Cookbook. A field is one piece of information on an entity. A field has a type:

A field can be required, and it can have a default, which a record gets when it is written without a value. A not-null field always holds a value: it needs a default, and existing records without a value are given it. A file or related field has no default, and a reference, related or file field can't be not null.

Each entity and enum has a GraphQL type name, which comes from its name unless you give one. It can't be the name of a type the generated API has for itself, such as Query, User, File, FileUpload or HttpHeader. MultiPaaS refuses that change, so give the entity or enum another type name. In an application with workflows, WorkflowRun and WorkflowRunStatus are such type names too, and WorkflowRun is such a plural name, because it makes the generated query workflowRun. They are refused with WORKFLOW_RUN_NAME_CLASH, as is the first workflow in an application that has such an entity or enum, so give it another type name, and another plural name when the plural clashes, or delete the workflows.

Each entity's and enum's type name also reserves names the generated API builds from it, such as ItemFilter, ItemOrder, ItemPage, ItemVersion and ItemReferenceFilter for Item, or StatusFilter for an enum Status, and two entities or enums can't reserve the same name. An entity named ItemReference beside Item is refused, because both reserve ItemReferenceFilter. Give one of them another type name; both keep their names.

Files

A record can hold a file, in a file field. Add the field in the MultiPaaS web app's field editor, or with multipaas field add --app APP_ID --entity ENTITY_ID --name NAME --type file, which needs CLI 1.1.0 or later. Add --max-file-bytes BYTES for a maximum size below the default of 512 MiB. A file field can be required, but it has no default. It can't be used to filter or order a list. An app pinned to an API version made before file fields has no file field in its API: to use one, move the app to a newer version.

The generated API takes a file in three steps. Your app's server can make them, or your end user's browser can:

The user who asks for an upload is the only one who can put its file id on a record, so make the request and the record write as that user: a file a user uploads from their browser can't be bound with an app identity's token, and one your server uploads as an app identity can't be bound with a user's token. A token refreshed for the same user works. The PUT carries only the headers the upload returned, never an access token. The generated API and file storage both accept requests from any origin, so a browser needs no proxy. Build on the generated API has code for a browser upload and says what changes on a server.

Reading the field returns the file's name, content type and size, and a link that works for 15 minutes. The link is fresh on every read, so ask for it when you show the file. Anyone who has the link can fetch the file until it expires, so don't store or share it. A record the caller can't read returns no link. Read the record with the requesting user's own access token when you show it to that user: a read with an app identity's token doesn't check the user. The link shows images (except SVG), audio, video and PDF in place, and downloads anything else.

Replacing a record's file, or clearing it with clear, keeps the old file, and the record's earlier versions return the file each one had. Deleting or restoring a record leaves its files as they are. An upload that no record holds may be removed a day after it was asked for, so put its file id on a record soon after the PUT. An import can carry files: put them in the import's files folder and name each in a line's file field.

Enums

An enum is a fixed list of allowed values, such as Open, In progress and Done. You declare it once. Several fields can share it.

A recipe belongs to a cookbook. You model that with a reference field on Recipe that points at Cookbook.

A related field is the other direction. Add one to Cookbook, and it lists the cookbook's recipes. It adds no data of its own. It reads the references that already exist.

A reference can point at its own entity. A parent reference on Session, with a children related field over it, lets each session list its child sessions.

Constraints

A unique constraint makes a set of fields unique together. For example, no two recipes in a cookbook share a title. An entity can have up to 10 unique constraints, each over a different set of fields, and each is checked on its own. MultiPaaS refuses a constraint that existing records already break. A constraint holds within one app-tenant, and among one environment's app-wide records, so two app-tenants or two environments can hold the same values. Because the model is shared, adding a constraint checks every live environment of the application.

Descriptions

An entity, a field, an enum and each value of an enum can carry a description: plain text, up to 1000 characters, saying what it means. A description is optional. Clearing one, or saving only blanks, leaves none. Set them in the web console or with the multipaas CLI, as Model your data shows.

Changing a description is a model change like any other, so it makes a new API version. Agents that connect to your app see your descriptions in the tools and inputs they get, so they know what each entity and field is for.

Changing the model

A change to the model takes effect immediately, and there is no publish step. Each change produces a new API version. You can also make a version of the same model to get newer API features.

You delete something you no longer want. MultiPaaS refuses to delete something that another part of the model still depends on. It tells you what to delete first. Deleting an entity, enum, field or constraint marks it deleted in the model. A deleted entity, enum or field stays in the earlier API versions that had it, and a deleted field's values stay on the records.

Some changes are refused because they would rewrite records that already exist. Add a new field instead.

Workflows

A workflow is part of the model too: a list of steps that change records together, all or nothing, which your app runs with one call. Like an entity or a field, declaring, changing or deleting one is a model change, so it makes a new API version. A version made after a workflow is declared or changed has a mutation for it as it stands then, and a version made after it is deleted has none. Earlier versions keep the mutation they had. Run workflows shows how.

Records

Data that fits the model is stored as records. A record belongs to one entity, and to one app-tenant or to the application as a whole.