pb.config.ts reference
pb.config.ts describes your app's collections: for each one, its name, major version, description and fields. npx phibac deploy publishes it as each collection's schema (the description the server checks every record against), and npx phibac generate turns the published schemas into TypeScript types. This page lists every helper the file is written with, every option, and the rules the server applies. Define your data walks through the same file step by step.
The file
The file is TypeScript (or JavaScript) that runs in Node.js when the CLI reads it. It imports the helpers from the CLI's package, as import { defineApp } from "phibac" does, and has one default export, made with defineApp:
import { defineApp, collection, string, number, integer, boolean, datetime, enumOf, json, fileRef, recordRef } from "phibac";
export default defineApp({
app: "app_...",
collections: {
"com.example.notes.note": collection({
version: 1,
description: "A note written by the user",
fields: {
text: string({ description: "Note text", maxLength: 20000, required: true }),
pinned: boolean({ description: "Whether the note is pinned", indexed: true }),
color: enumOf(["yellow", "blue", "green"], { description: "The colour the note is shown in", indexed: true }),
priority: integer({ description: "Priority from 1 (low) to 3 (high)", min: 1, max: 3, indexed: true }),
weight: number({ description: "How much the note matters, from 0 to 1", min: 0, max: 1 }),
remindAt: datetime({ description: "When to remind the user of the note", indexed: true }),
place: string({ description: "Where the user was when they wrote the note", maxLength: 200, sensitive: true }),
photo: fileRef({ description: "A photo attached to the note" }),
checklist: json({ description: "A checklist in the note: a list of items, each with a text and whether it is done" }),
},
}),
"com.example.notes.comment": collection({
version: 1,
description: "A comment the user wrote on a note",
fields: {
note: recordRef({ description: "The note this comment is about", indexed: true, required: true }),
text: string({ description: "Comment text", maxLength: 2000, required: true }),
},
}),
},
});
Each helper only returns a plain description of what you wrote. The CLI checks the whole file when it reads it, before anything is sent, and stops with an error that names the collection and field. The server checks the same rules again when you publish.
Sandbox collections (named sandbox.<name>) need no schema and do not go in this file.
defineApp
defineApp(def: AppDef): AppDef
The file's default export. AppDef has two properties:
app(string, required): your app's ID, which starts withapp_.npx phibac initwrites it.npx phibac deploypublishes for this app, so your developer token must belong to the account that owns it.collections(required): an object that maps each collection's name to acollection({ ... }). An empty object is allowed:npx phibac deploythen has nothing to publish.
collection
collection(def: CollectionDef): CollectionDef
One collection. CollectionDef has three properties, all required:
version(number): the collection's major version, a whole number of at least 1. A new collection starts at 1. Raise it by exactly one to publish a breaking change (see Versions and breaking changes).description(string): what the collection holds, written for a person. When another app asks the user for permission to read the collection, the consent page names it with this description. It must not be empty.fields: an object that maps each field's name to a field helper. At least one field.
The server adds the minor version itself; you never write it.
Field helpers
There is one helper per field type. Each takes an options object, and enumOf also takes the list of values first.
| Helper | Type on the server | A value must be | Type in generated code |
|---|---|---|---|
string(options) |
string |
Text. | string |
number(options) |
number |
Any finite number. | number |
integer(options) |
integer |
A whole number. | number |
boolean(options) |
boolean |
true or false. |
boolean |
datetime(options) |
datetime |
Text in RFC 3339 form, such as "2026-11-14T09:30:00.000Z". |
string |
enumOf(values, options) |
enum |
One of the strings in values. |
The union of the values |
json(options) |
json |
Any JSON value. | unknown |
fileRef(options) |
fileRef |
A file ID from files.upload, starting with f_. |
string |
recordRef(options) |
recordRef |
Text starting with pb://, a record's global ID. The server does not check that the record exists. |
string |
Queries compare datetime values as text, so write every value the same way, with new Date().toISOString() (Define your data explains why).
Field options
Every helper accepts these options:
description(string, required): what the field holds, written for a person. It becomes a comment in the generated types and is part of the published schema, which anyone can read. It must not be empty.required(boolean): every record must have the field; leaving it out or setting it tonullis refused withschema_violation. Without it the field is optional.indexed(boolean): queries may filter and sort on the field. Queries can use only indexed fields,createdAtandupdatedAt. Not allowed onjson.sensitive(boolean): the consent page marks the field "(sensitive)" when another app asks the user for permission to read the collection. It does not change who can read the field.
Some helpers accept more:
maxLength(number,stringonly): the most characters the text may have, a whole number of at least 1.minandmax(number,numberandintegeronly): the smallest and largest value allowed. Each is optional and must be a finite number;minmay not be greater thanmax.values(enumOfonly, given as its first argument): the allowed strings. At least one; each must be a non-empty string, and no value may appear twice.
A record that breaks a rule is refused with schema_violation, and the error lists each field with the reason, such as required, longer than maxLength, below min, not one of the allowed values or unknown field. A record may hold only the fields its schema lists.
The options are checked by name: an option with another name, or a misspelled one, stops npx phibac deploy with an error that lists the allowed options. TypeScript also refuses an option a helper does not accept, such as maxLength on integer or indexed on json.
Naming rules
Collection names are written like a reversed web address, such as com.example.notes.note:
- At least three parts separated by dots.
- Each part starts with a lower-case letter and uses only lower-case letters, digits and
-. - At most 128 characters in all.
- Names starting with
core.orsandbox.are reserved and cannot be published. - The first app to publish a name owns it. Only that app can publish new versions of it and write records to it; publishing a name another app owns fails with
forbidden. On a shared server, start your names with a domain you control.
Field names:
- Start with a letter and use only letters (upper or lower case), digits and
_. - At most 64 characters.
createdAtandupdatedAtare reserved: every record already has them.
A name that breaks a rule stops npx phibac deploy with an error before anything is sent, and the server refuses it with invalid_request.
Versions and breaking changes
npx phibac deploy compares each collection with the latest published version of the same major version (version):
- Same: nothing changed. Nothing is published.
- Additive: the change keeps every existing record and app working. It is published as a new minor version of the same major version, such as 1.1 after 1.0.
- Breaking: the change could make existing records or apps wrong.
npx phibac deployshows the collection asbreaking, with the reasons, and publishes nothing (the server's code isschema_incompatible). Publish it as the next major version instead, by raisingversionby one.
Which changes are which:
| Change | Kind | Reason shown |
|---|---|---|
Change the collection's description |
additive | |
Add a field that is not required |
additive | |
Change a field's description, indexed or sensitive |
additive | |
Raise maxLength, or remove it |
additive | |
Lower min, raise max, or remove either |
additive | |
Add a value to enumOf |
additive | |
| Remove a field (renaming removes it) | breaking | field removed: <field> |
| Change a field's type | breaking | type changed: <field> |
Add required: true to an existing field |
breaking | now required: <field> |
Remove required: true |
breaking | no longer required: <field> |
Add a field that is required |
breaking | new required field: <field> |
Add maxLength, or lower it |
breaking | maxLength reduced: <field> |
Add min or max, raise min or lower max |
breaking | range narrowed: <field> |
Remove a value from enumOf |
breaking | enum value removed: <field>.<value> |
Reordering the values of an enumOf, or publishing the same definition again, is same.
Rules for version:
- The first time a name is published,
versionmust be 1. - A new major version must be the latest plus one: you cannot skip a number. Its fields can be anything; it is not compared with the major version before it.
- No published schema version is ever deleted. Older major versions stay published, records keep the major version they were written with until an update moves them to another, and an additive change can still be published to an older major version.
Change your schema safely shows a breaking change published as version 2, and how to handle the records written with version 1.
Exported types
Besides the helpers, the same package exports the types they use, for when you build a config in code: AppDef, CollectionDef, FieldDef (what a field helper returns), FieldType (the nine type names), BaseOptions (the options every helper takes), StringOptions (adds maxLength) and NumberOptions (adds min and max).