Skip to content

ResourceModel

ResourceModel = object

Defined in: packages/schema/src/model.ts:122

A resource as the server and the app see it: a table, its fields and what the API does with them, built by resource(...).toModel(); see resource().

optional author?: string

Defined in: packages/schema/src/model.ts:157

The field holding the id of the user who created the record (.author()): creates set it, no request may.


optional buckets?: BucketsModel

Defined in: packages/schema/src/model.ts:201

The resource it is a time rollup of, and how (.bucketsOf()): the database writes its rows, the API only reads them.


optional checks?: Record<string, CheckModel>

Defined in: packages/schema/src/model.ts:199

The database checks whose refusal the API names, by constraint name, each with the label shown for it (.checks()).


optional comments?: true

Defined in: packages/schema/src/model.ts:178

Whether people who may read its records comment on them (.comments()).


optional derived?: DerivedModel[]

Defined in: packages/schema/src/model.ts:203

The values worked out from other records for each of its records, kept current by Protobase (.derive()).


optional etagFrom?: string

Defined in: packages/schema/src/model.ts:187

The field whose change makes a record’s new ETag (.etagFrom()), in place of a version or updated_at column found by name.


optional events?: EventModel[]

Defined in: packages/schema/src/model.ts:172

The events its changes raise (.events()), the catalogue subscriptions pick from.


optional explicitGrants?: true

Defined in: packages/schema/src/model.ts:189

Whether role wildcards such as *.read leave it out, so only * and capabilities naming it grant it (.explicitGrants()).


fields: Record<string, FieldModel>

Defined in: packages/schema/src/model.ts:133

Its fields, by field name: each a column of its table.


optional history?: true

Defined in: packages/schema/src/model.ts:174

Whether every change of its records is kept, with who made it (.history()).


optional historyIgnore?: string[]

Defined in: packages/schema/src/model.ts:176

The fields whose changes are not captured (.history({ ignore })): an update of only those keeps nothing.


optional links?: readonly [string, string]

Defined in: packages/schema/src/model.ts:170

The two relations a link resource joins (.links()), so each side lists the other at /{parent}/{key}/{resource}.


optional live?: true

Defined in: packages/schema/src/model.ts:180

Whether open pages refresh as soon as its records change (.live()).


optional liveReads?: string[]

Defined in: packages/schema/src/model.ts:185

The resources whose changes refresh its open pages in place of its own (.live({ reads })), for one backed by a database view: its own table is not captured, and a change names no record of it.


optional lookups?: Record<string, FieldModel>

Defined in: packages/schema/src/model.ts:138

Its lookup fields, by field name (.lookup()): each shows a field of a linked record and has no column of its own. A read’s model, such as /meta’s, has those the caller may read among its fields instead.


name: string

Defined in: packages/schema/src/model.ts:124

The resource’s name: its address (/api/v1/<name>, /<name> in the admin) and how other config refers to it.


optional openExisting?: string[]

Defined in: packages/schema/src/model.ts:194

The fields of a unique key whose conflict on create answers the record already holding those values, to a caller who may read it (.openExisting()).


optional owner?: string

Defined in: packages/schema/src/model.ts:155

The field holding the owning user’s id; .own capability scopes filter on it.


optional parents?: ParentModel[]

Defined in: packages/schema/src/model.ts:168

The records its records belong to, and the access on them writing its records needs (.parent()).


optional position?: object

Defined in: packages/schema/src/model.ts:159

The integer field holding the records’ order by hand (.position()), 1 the first.

optional after?: PositionAfterModel

The records each record ranks after while they are pending, such as the tasks it waits for (.position(..., { after })).

field: string

The integer field, 1 the first record.

optional within?: string

The relation whose records each have an order of their own, as an invoice’s items do; one order for all records when omitted.


primaryKey: string[]

Defined in: packages/schema/src/model.ts:140

The fields of its key, in order; records are addressed by it.


optional search?: string[]

Defined in: packages/schema/src/model.ts:151

Field names that the bare-text search filter matches against.


optional searchMatch?: Record<string, SearchMatch>

Defined in: packages/schema/src/model.ts:153

How a search field matches when not by containing the word; see SearchMatch.


optional softDelete?: string

Defined in: packages/schema/src/model.ts:142

The field a delete sets instead of removing the row, and lists leave such rows out (.softDelete()).


table: object

Defined in: packages/schema/src/model.ts:126

The table it reads and writes.

name: string

The table’s name.

optional schema?: string

The table’s schema; the search path decides when omitted.


optional tenant?: string

Defined in: packages/schema/src/model.ts:144

The field that separates tenants: every query is limited to the caller’s tenant (.tenant()).


optional tenantAcross?: "memberships"

Defined in: packages/schema/src/model.ts:149

memberships: lists also read the other tenants the caller is a member of, each as the caller’s role there allows (.tenant(pick, { across })); a record’s own reads and every write stay in the caller’s tenant.