@protobase/cli 0.117.6 → 0.117.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/package.js +1 -1
- package/dist/doctor/lookup-issues.js +23 -0
- package/dist/doctor/lookup-models.js +35 -0
- package/dist/doctor/read-shapes.js +15 -2
- package/dist/doctor/run-without-database.js +4 -2
- package/dist/doctor/run.js +8 -4
- package/package.json +8 -8
- package/skills/protobase/SKILL.md +1 -1
- package/skills/protobase/references/features/data-model.md +1 -0
- package/skills/protobase/references/reference/cli.md +2 -2
- package/skills/protobase/references/reference/data-config.md +65 -0
package/dist/cli/package.js
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { tableKey } from "../db/model.js";
|
|
2
|
+
import { hasUniqueIndexOn } from "../db/keys.js";
|
|
3
|
+
//#region src/doctor/lookup-issues.ts
|
|
4
|
+
const quoteIdent = (name) => `"${name.replaceAll("\"", "\"\"")}"`;
|
|
5
|
+
/**
|
|
6
|
+
* A lookup field that reads the one record of another resource pointing at each record needs a unique index on that
|
|
7
|
+
* relation: without one a record may have several, and every read of the field fails.
|
|
8
|
+
*/
|
|
9
|
+
const lookupIssues = (model, models, tables) => Object.values(model.lookups ?? {}).flatMap((field) => {
|
|
10
|
+
const { from, via } = field.lookup;
|
|
11
|
+
const linked = from === void 0 ? void 0 : models.find((each) => each.name === from);
|
|
12
|
+
const column = linked && Object.hasOwn(linked.fields, via) ? linked.fields[via].column : void 0;
|
|
13
|
+
const table = linked && tables.find((each) => each.schema === (linked.table.schema ?? "public") && each.name === linked.table.name);
|
|
14
|
+
if (!column || !table || table.kind === "view" || hasUniqueIndexOn(table, [column])) return [];
|
|
15
|
+
return [{
|
|
16
|
+
severity: "error",
|
|
17
|
+
resource: model.name,
|
|
18
|
+
message: `${field.name}: looks up the one ${from} record whose "${via}" points at each record, but no unique index on ${tableKey(table)} (${column}) makes it one, so a read fails once a record has two`,
|
|
19
|
+
suggestion: `create unique index on ${quoteIdent(table.schema)}.${quoteIdent(table.name)} (${quoteIdent(column)});`
|
|
20
|
+
}];
|
|
21
|
+
});
|
|
22
|
+
//#endregion
|
|
23
|
+
export { lookupIssues };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { withLookupRead } from "@protobase/query";
|
|
2
|
+
import { lookupLink } from "@protobase/schema/internal";
|
|
3
|
+
//#region src/doctor/lookup-models.ts
|
|
4
|
+
/**
|
|
5
|
+
* The models as the scan guard judges a read of them: each with its lookup fields among its fields, read in no
|
|
6
|
+
* caller's scope, since doctor judges what any caller may ask. A lookup whose linked record cannot be found is left
|
|
7
|
+
* out; the server's startup check names it.
|
|
8
|
+
*/
|
|
9
|
+
const lookupReadModels = (models) => {
|
|
10
|
+
const byName = new Map(models.map((model) => [model.name, model]));
|
|
11
|
+
return models.map((model) => {
|
|
12
|
+
const { lookups, ...rest } = model;
|
|
13
|
+
if (!lookups) return model;
|
|
14
|
+
const read = Object.values(lookups).flatMap((field) => {
|
|
15
|
+
const link = lookupLink(model, field, (name) => byName.get(name));
|
|
16
|
+
return link ? [[field.name, withLookupRead(field, {
|
|
17
|
+
model: link.linked,
|
|
18
|
+
scope: {},
|
|
19
|
+
conditions: [],
|
|
20
|
+
value: link.value,
|
|
21
|
+
match: link.match,
|
|
22
|
+
link: link.link
|
|
23
|
+
})]] : [];
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
...rest,
|
|
27
|
+
fields: {
|
|
28
|
+
...model.fields,
|
|
29
|
+
...Object.fromEntries(read)
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { lookupReadModels };
|
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
import { viewShapes } from "./view-shapes.js";
|
|
2
2
|
import { pageShapes } from "./page-shapes.js";
|
|
3
3
|
import { fieldShapes, lookupShapes } from "./field-shapes.js";
|
|
4
|
+
import { lookupQueries } from "@protobase/query";
|
|
4
5
|
//#region src/doctor/read-shapes.ts
|
|
6
|
+
const linkedShapes = (shape, byName) => {
|
|
7
|
+
const model = byName[shape.resource];
|
|
8
|
+
if (!model) return [];
|
|
9
|
+
return lookupQueries(model, shape.query).map(({ field, read, query }) => ({
|
|
10
|
+
resource: read.model.name,
|
|
11
|
+
request: shape.request,
|
|
12
|
+
from: `${shape.from}, through the lookup field "${field}"`,
|
|
13
|
+
query
|
|
14
|
+
}));
|
|
15
|
+
};
|
|
5
16
|
/**
|
|
6
17
|
* Every read the API takes of the resources and the app makes of them, which the scan guard judges when it runs: what
|
|
7
|
-
* the fields allow, the relations' lookups, each view's pages and each composed page's blocks
|
|
18
|
+
* the fields allow, the relations' lookups, each view's pages and each composed page's blocks, and the linked records
|
|
19
|
+
* each of them reads through a lookup field. `models` have their lookup fields among their fields (`lookupReadModels`).
|
|
8
20
|
*/
|
|
9
21
|
const readShapes = ({ models, views, pages }) => {
|
|
10
22
|
const byName = Object.fromEntries(models.map((model) => [model.name, model]));
|
|
11
|
-
|
|
23
|
+
const shapes = [
|
|
12
24
|
...models.flatMap((model) => [...fieldShapes(model), ...lookupShapes(model, byName)]),
|
|
13
25
|
...views.flatMap((view) => viewShapes(view, byName)),
|
|
14
26
|
...pages.flatMap((page) => pageShapes(page, byName, views))
|
|
15
27
|
];
|
|
28
|
+
return [...shapes, ...shapes.flatMap((shape) => linkedShapes(shape, byName))];
|
|
16
29
|
};
|
|
17
30
|
//#endregion
|
|
18
31
|
export { readShapes };
|
|
@@ -3,6 +3,7 @@ import { userTablesOn } from "../config/user-tables-config.js";
|
|
|
3
3
|
import { readMigrationSql } from "./migration-sql.js";
|
|
4
4
|
import { captureFileIssues } from "./capture-files.js";
|
|
5
5
|
import { formatIssue, loadDoctorProject, unplannedNotes } from "./project.js";
|
|
6
|
+
import { lookupReadModels } from "./lookup-models.js";
|
|
6
7
|
import { readShapes } from "./read-shapes.js";
|
|
7
8
|
import { relationIssues } from "./relation-issues.js";
|
|
8
9
|
import { sortIssues } from "./sort-issues.js";
|
|
@@ -19,14 +20,15 @@ const runDoctorWithoutDatabase = async (options, out) => {
|
|
|
19
20
|
const project = await loadDoctorProject(options.configDir, options.projectDir);
|
|
20
21
|
const { config, source, builtIn } = project;
|
|
21
22
|
const models = [...builtIn.models, ...config.models];
|
|
23
|
+
const read = lookupReadModels(models);
|
|
22
24
|
const shapes = readShapes({
|
|
23
|
-
models,
|
|
25
|
+
models: read,
|
|
24
26
|
views: [...builtIn.views, ...config.views],
|
|
25
27
|
pages: config.pages
|
|
26
28
|
});
|
|
27
29
|
const served = configExports(await projectResources(source)).resources.map((resource) => resource.toModel());
|
|
28
30
|
const capture = captureFileIssues(served, source.events, await readMigrationSql(options.projectDir) ?? "");
|
|
29
|
-
const issues = [...models.flatMap((model) => [...relationIssues(model, models), ...sortIssues(
|
|
31
|
+
const issues = [...models.flatMap((model, i) => [...relationIssues(model, models), ...sortIssues(read[i], shapes)]), ...capture.issues];
|
|
30
32
|
for (const issue of issues) out(formatIssue(issue));
|
|
31
33
|
for (const note of unplannedNotes(project, models)) out(note);
|
|
32
34
|
const errors = issues.filter((i) => i.severity === "error").length;
|
package/dist/doctor/run.js
CHANGED
|
@@ -4,6 +4,7 @@ import { connect } from "../db/connect.js";
|
|
|
4
4
|
import { introspect } from "../db/introspect.js";
|
|
5
5
|
import { builtInIndexIssues } from "./built-in-models.js";
|
|
6
6
|
import { formatIssue, loadDoctorProject, unplannedNotes } from "./project.js";
|
|
7
|
+
import { lookupReadModels } from "./lookup-models.js";
|
|
7
8
|
import { readShapes } from "./read-shapes.js";
|
|
8
9
|
import { relationIssues } from "./relation-issues.js";
|
|
9
10
|
import { sortIssues } from "./sort-issues.js";
|
|
@@ -11,6 +12,7 @@ import { checkServerStartup } from "./startup.js";
|
|
|
11
12
|
import { readOnlyDb } from "../db/read-only-db.js";
|
|
12
13
|
import { checkResource } from "./check.js";
|
|
13
14
|
import { fileIndexIssues, indexIssues } from "./index-issues.js";
|
|
15
|
+
import { lookupIssues } from "./lookup-issues.js";
|
|
14
16
|
import { userTableModels } from "./user-table-models.js";
|
|
15
17
|
import pg from "pg";
|
|
16
18
|
import { tableIndexes } from "@protobase/query";
|
|
@@ -30,19 +32,21 @@ const runDoctor = async (options, out) => {
|
|
|
30
32
|
...config.models,
|
|
31
33
|
...userTables.models
|
|
32
34
|
];
|
|
35
|
+
const read = lookupReadModels(models);
|
|
33
36
|
const shapes = readShapes({
|
|
34
|
-
models,
|
|
37
|
+
models: read,
|
|
35
38
|
views: [...builtIn.views, ...config.views],
|
|
36
39
|
pages: config.pages
|
|
37
40
|
});
|
|
38
|
-
const indexes = await Promise.all(models.map(async (model) => {
|
|
41
|
+
const indexes = await Promise.all(models.map(async (model, i) => {
|
|
39
42
|
const table = await tableIndexes(db, model);
|
|
40
|
-
return [...indexIssues(
|
|
43
|
+
return [...indexIssues(read[i], table, shapes), ...fileIndexIssues(model, table)];
|
|
41
44
|
})).then((found) => found.map((issues, i) => i < builtIn.models.length ? builtInIndexIssues(issues) : issues)).finally(() => db.destroy());
|
|
42
45
|
const issues = [...userTables.issues, ...models.flatMap((model, i) => [
|
|
43
46
|
...checkResource(model, tables),
|
|
44
47
|
...relationIssues(model, models),
|
|
45
|
-
...
|
|
48
|
+
...lookupIssues(model, models, tables),
|
|
49
|
+
...sortIssues(read[i], shapes),
|
|
46
50
|
...indexes[i]
|
|
47
51
|
])];
|
|
48
52
|
for (const issue of issues) out(formatIssue(issue));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.117.
|
|
3
|
+
"version": "0.117.7",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.117.
|
|
47
|
-
"@protobase/layout": "0.117.
|
|
48
|
-
"@protobase/query": "0.117.
|
|
49
|
-
"@protobase/schema": "0.117.
|
|
50
|
-
"@protobase/server": "0.117.
|
|
51
|
-
"@protobase/ui": "0.117.
|
|
52
|
-
"@protobase/workflows": "0.117.
|
|
46
|
+
"@protobase/config": "0.117.7",
|
|
47
|
+
"@protobase/layout": "0.117.7",
|
|
48
|
+
"@protobase/query": "0.117.7",
|
|
49
|
+
"@protobase/schema": "0.117.7",
|
|
50
|
+
"@protobase/server": "0.117.7",
|
|
51
|
+
"@protobase/ui": "0.117.7",
|
|
52
|
+
"@protobase/workflows": "0.117.7",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -71,7 +71,7 @@ Reference:
|
|
|
71
71
|
- When setting the assistant, maps or plugins in the config → read [Admin app options](references/reference/config/admin-app.md)
|
|
72
72
|
- When setting `jobs`, `events`, `history`, `webhooks` or `notifications` in the config → read [Jobs and events options](references/reference/config/jobs-and-events.md)
|
|
73
73
|
- When setting `files` in the config → read [Files options](references/reference/config/files.md)
|
|
74
|
-
- When defining resources, fields, keys, relations, rollups, formulas and validation → read [Data config](references/reference/data-config.md)
|
|
74
|
+
- When defining resources, fields, keys, relations, rollups, formulas, lookups and validation → read [Data config](references/reference/data-config.md)
|
|
75
75
|
- When defining views, columns, filters, charts, related records and actions → read [UI config](references/reference/ui-config.md)
|
|
76
76
|
- When asking how the packages fit together → read [Architecture](references/reference/architecture.md)
|
|
77
77
|
- When calling or changing the REST API, its filters, writes and errors → read [REST API](references/reference/api.md)
|
|
@@ -17,6 +17,7 @@ Describe the tables of an existing Postgres database as resources, with their fi
|
|
|
17
17
|
- [Opening an existing record](../reference/data-config.md#opening-an-existing-record): A create that repeats a record's unique values, such as a direct message with the same people, opens that record instead of failing, for whoever may read it; anyone else gets the usual conflict, which does not say the record exists.
|
|
18
18
|
- [Record validation](../reference/data-config.md#resource): A rule over the whole record runs on every create and update and reports each problem on the field it concerns.
|
|
19
19
|
- [Rollups and formulas](../reference/data-config.md#rollups-and-formulas) (beta): Fields that hold counts, sums, averages, minimums or maximums of related records, or values calculated from the record's own numbers, kept current by the database.
|
|
20
|
+
- [Lookups](../reference/data-config.md#lookups) (beta): A field can show a field of a linked record, such as an order's customer name, read with the record in the same query and only as far as the caller may read the linked record.
|
|
20
21
|
- [Time rollups](../reference/data-config.md#time-rollups) (in development): A large events table gets an hourly or daily rollup table that the app's migrations create, so charts over months of millions of rows can read a few thousand rows instead.
|
|
21
22
|
- [Sensitive fields](../reference/data-config.md#sensitive-fields): Values such as bank account numbers are left out of every response and shown masked. A permitted user reveals one value at a time, and each reveal is audited.
|
|
22
23
|
- [Recent strong sign-in](../reference/data-config.md#recent-strong-sign-in): A sensitive field can ask for a passkey or a second step in the last minutes before it is revealed, or an emailed code for an account with neither. The record page asks the person to confirm it's them, then shows it.
|
|
@@ -111,8 +111,8 @@ A config that exports no resource fails, as one that lost its resources by mista
|
|
|
111
111
|
|
|
112
112
|
Imports `config/index.ts` and the views of `config/*/ui.ts`, as the config module has them by convention, and checks every exported resource against the database, with the resources Protobase adds by what `protobase.config.ts` (read with `command: 'tool'`) and the resources enable: the [webhook](webhooks.md#subscriptions-in-the-admin-app) ones of `webhooks`, Failed jobs, [Activity](history.md) and [Comments](comments.md). The tables [`migration`](#migration) writes for those have every index their reads need, so after the project's migrations they pass; a read of theirs that lacks an index, as on a table an earlier version wrote, is an error and doctor exits 1 until you run `migration` and apply what it writes:
|
|
113
113
|
|
|
114
|
-
- error: missing table or column, field type that does not fit the column (a file field needs a text column), table without a usable key, configured key not backed by a unique index, `.openExisting()` fields that are not the columns of a unique index, relation to a resource the config does not declare
|
|
115
|
-
- error: a read the [scan guard](api.md#safety) refuses, because no index serves a column it filters, sorts, searches or counts by. Doctor reads each table's indexes from the catalog, as the server does, and judges with the scan guard's own rule every read the API takes and the app makes: a filter on each `.filterable()` field, a sort by each `.sortable()` one, `search()` over the search fields, a role's own records (`.owner()`)
|
|
114
|
+
- error: missing table or column, field type that does not fit the column (a file field needs a text column), table without a usable key, configured key not backed by a unique index, `.openExisting()` fields that are not the columns of a unique index, relation to a resource the config does not declare, a [lookup field](data-config.md#lookups) of the one record of another resource without a unique index on the relation it reads that record by
|
|
115
|
+
- error: a read the [scan guard](api.md#safety) refuses, because no index serves a column it filters, sorts, searches or counts by. Doctor reads each table's indexes from the catalog, as the server does, and judges with the scan guard's own rule every read the API takes and the app makes: a filter on each `.filterable()` field, a sort by each `.sortable()` one, `search()` over the search fields, a role's own records (`.owner()`), the names a relation shows and the linked records a lookup field reads, judged against the linked table; each view's list in its order and with the filter it opens with, its filter widgets and their counts, its chart, its map, board, calendar and timeline, its card photos, its order by hand, its related sections, galleries and charts, its named lists, its recent records and a saved search's new records; and each read of a [composed page's read plan](layouts.md#how-a-page-reads-its-data): its blocks' lists, counts and aggregates, a `Chart`'s grouped and split fields, a nested list's `limit_per`, and the outer read each `related()` term carries with its own filter and order. Each error is an index to add, with every request that needs it and where it comes from:
|
|
116
116
|
|
|
117
117
|
```
|
|
118
118
|
error agencies: no index serves the column "name", so the API refuses:
|
|
@@ -118,6 +118,7 @@ Every option returns a new [field](https://docs.protobase.net/api/schema/interfa
|
|
|
118
118
|
| `.ai({ prompt })` | A job fills the field from `prompt`, `{{field}}` replaced by the record's values, after a create and after an update of a field the prompt reads, as the user who wrote. Text or enum, optional. See [AI fields and actions](ai.md). |
|
|
119
119
|
| `.rollup({ from, via, fn, field })` | The database keeps the field from the records of another resource: their count, sum, average, least or greatest value. Read-only. See [Rollups and formulas](#rollups-and-formulas). |
|
|
120
120
|
| `.formula(expression)` | The database computes the field from the record's other number fields, as a generated column. Read-only. See [Rollups and formulas](#rollups-and-formulas). |
|
|
121
|
+
| `.lookup({ via, field, from? })` | Shows a field of the record this one is linked to, read with the record. Read-only. See [Lookups](#lookups). |
|
|
121
122
|
|
|
122
123
|
The ERP's products show most of them, together with soft delete and a tenant:
|
|
123
124
|
|
|
@@ -209,6 +210,70 @@ Empty values of `field` are left out, as in SQL. The migration adds the column,
|
|
|
209
210
|
|
|
210
211
|
Neither field can be written through the API, have a default, or be sensitive, an AI field, a file, or the key, tenant, owner or soft delete field, and a formula cannot read a sensitive field. The server does not start while a declared column, function or trigger is missing or out of date, with a message that names the fields; the migration fixes that. It stops with an error, without writing anything, when the column already exists as the project's own: a plain column where a formula is declared, a generated column it did not write, or a rollup column of another type.
|
|
211
212
|
|
|
213
|
+
## Lookups
|
|
214
|
+
|
|
215
|
+
:::caution[Beta]
|
|
216
|
+
Not yet:
|
|
217
|
+
|
|
218
|
+
- <gap>Sorting by a lookup field reads every record the list keeps before it returns a page, because no index orders one table by another table's column.</gap>
|
|
219
|
+
- <gap>A lookup field cannot show a relation or a file because reading the linked record's key or stored file for it is not implemented.</gap>
|
|
220
|
+
- <gap>A lookup through a relation of several columns, or to a resource with a key of several fields, is not supported yet.</gap>
|
|
221
|
+
- <gap>A list across organizations (`across: 'memberships'`) cannot show lookup fields of another organization's records because reading their linked records under that organization's access is not implemented.</gap> They are empty there.
|
|
222
|
+
- <gap>An open page of a [live](live.md) resource cannot refresh when only a linked record changes because capturing those changes for the lookup fields that read them is not implemented.</gap>
|
|
223
|
+
:::
|
|
224
|
+
|
|
225
|
+
A **lookup field** shows a field of the record its record is linked to, such as an order's customer name. It has no column of its own: the API reads it with the record, in the same query, from the linked table, so it always shows the linked record's current value.
|
|
226
|
+
|
|
227
|
+
```ts title="docs-examples/reference/lookups.ts"
|
|
228
|
+
import { f, resource } from '@protobase/schema'
|
|
229
|
+
|
|
230
|
+
// Orders show their customer's name and tier through their own relation to the customer, and each customer the name
|
|
231
|
+
// of their one account manager, whose record points at the customer.
|
|
232
|
+
|
|
233
|
+
/** shop.customers: one row per customer. */
|
|
234
|
+
export const customers = resource('customers')
|
|
235
|
+
.table('shop.customers')
|
|
236
|
+
.fields({
|
|
237
|
+
id: f.integer().readOnly().filterable().sortable().dbDefault(),
|
|
238
|
+
name: f.text().filterable().sortable(),
|
|
239
|
+
tier: f.enum(['gold', 'silver', 'bronze']).filterable(),
|
|
240
|
+
// From the one manager record whose customer_id is this customer; empty without one.
|
|
241
|
+
manager_name: f.text().lookup({ from: 'account_managers', via: 'customer_id', field: 'name' }),
|
|
242
|
+
})
|
|
243
|
+
.primaryKey((r) => r.id)
|
|
244
|
+
|
|
245
|
+
/** shop.account_managers: at most one per customer, by a unique index on customer_id. */
|
|
246
|
+
export const accountManagers = resource('account_managers')
|
|
247
|
+
.table('shop.account_managers')
|
|
248
|
+
.fields({
|
|
249
|
+
id: f.integer().readOnly().filterable().dbDefault(),
|
|
250
|
+
customer_id: f.relation('customers').filterable(),
|
|
251
|
+
name: f.text(),
|
|
252
|
+
})
|
|
253
|
+
.primaryKey((r) => r.id)
|
|
254
|
+
|
|
255
|
+
/** shop.orders: one row per order. */
|
|
256
|
+
export const orders = resource('orders')
|
|
257
|
+
.table('shop.orders')
|
|
258
|
+
.fields({
|
|
259
|
+
id: f.integer().readOnly().filterable().sortable().dbDefault(),
|
|
260
|
+
customer_id: f.relation('customers').filterable(),
|
|
261
|
+
// The customer's name and tier, as the caller may read them; filtered and sorted as the customer's fields are.
|
|
262
|
+
customer_name: f.text().lookup({ via: 'customer_id', field: 'name' }).filterable().sortable(),
|
|
263
|
+
customer_tier: f.enum(['gold', 'silver', 'bronze']).lookup({ via: 'customer_id', field: 'tier' }).filterable(),
|
|
264
|
+
})
|
|
265
|
+
.primaryKey((r) => r.id)
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
`.lookup({ via, field })` reads `field` of the record that the record's relation `via` points at. `.lookup({ from, via, field })` reads it of the one record of resource `from` whose relation `via` points at the record, such as a customer's account manager. That needs a unique index on `via`, which [`protobase doctor`](cli.md#doctor) asks for, since a second such record makes every read of the field fail.
|
|
269
|
+
|
|
270
|
+
- It is declared with the linked field's type, and for an enum its values. The server does not start while they differ, or while a resource or field it names is missing or the linked field is sensitive.
|
|
271
|
+
- It is read-only and optional: empty when there is no linked record, or none the caller may read.
|
|
272
|
+
- It shows in lists, record pages, `/meta` and the API as any read-only field does, and the response of a write has it too.
|
|
273
|
+
- `.filterable()` and `.sortable()` take it when the linked field takes them. A filter on it keeps the records whose link is among the keys of the linked records that match, so it needs an index on the linked field in the linked table and one on `via` in this one; the [scan guard](api.md#safety) and doctor ask for both, as for any other read. A sort by it needs them too. <gap>Sorting by a lookup field reads every record the list keeps before it returns a page, because no index orders one table by another table's column.</gap>
|
|
274
|
+
- It reads the linked records as the caller would: in their tenant, without soft-deleted ones, inside their row filter and the parents they read. A caller who may not read the linked resource, whose read rule there needs the record, or who may not read the linked field or the relation it goes through, does not have the lookup field at all: responses, `/meta`, filters and sorts leave it out, as they leave out any field the caller may not read. Its own `.access({ read })` narrows that further.
|
|
275
|
+
- It is not stored with the record, so the record's ETag, events, history and the filters of access rules do not see it, and it cannot be a key, tenant, owner, author, soft delete, position, parent, link or search field, or have a column, a default, a rollup, a formula or an AI prompt.
|
|
276
|
+
|
|
212
277
|
## Time rollups
|
|
213
278
|
|
|
214
279
|
:::caution[In development]
|