@softr/sdk 1.4.0 → 1.4.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @softr/sdk
2
2
 
3
+ ## 1.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - The `auth` skill's sign-out snippet redirects to `/login` with `signedOut: true`, so a login page that goes straight to single sign-on does not sign the visitor back in.
8
+ - The `record-queries`, `record-mutations`, `charts-and-metrics` and `current-user` skills teach `filter` on `defineQuery` and `defineMutation` as the way to keep each visitor to their own records, with `user.properties` for the Record ID of a link to Users, one action per role, and the errors a filter can throw.
9
+
3
10
  ## 1.4.0
4
11
 
5
12
  ### Minor Changes
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.4.0";
2
+ var version = "1.4.1";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: core
12
12
  library: softr-sdk
13
- library_version: 1.4.0
13
+ library_version: 1.4.1
14
14
  ---
15
15
 
16
16
  # Softr SDK core
@@ -13,7 +13,7 @@ description: >-
13
13
  metadata:
14
14
  type: sub-skill
15
15
  library: softr-sdk
16
- library_version: 1.4.0
16
+ library_version: 1.4.1
17
17
  ---
18
18
 
19
19
  **Boundary.** `ai` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineAiAction` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -102,7 +102,7 @@ const summarize = createServerFn({ method: 'POST' })
102
102
  })
103
103
  ```
104
104
 
105
- The record id comes from the browser, so it can name any deal. The read of `dealQuery` takes the table's scope, like every other read of the table. Where reps see only their own deals, a read without it briefs anyone on any deal: see [record-queries](../record-queries/SKILL.md#keep-each-visitor-to-their-own-records).
105
+ The record id comes from the browser, so it can name any deal. `dealQuery` takes the table's `filter`, like every other query of the table. Where reps see only their own deals, a query without it briefs anyone on any deal: see [record-queries](../record-queries/SKILL.md#keep-each-visitor-to-their-own-records).
106
106
 
107
107
  ## Extraction: an answer that is data
108
108
 
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.4.0
13
+ library_version: 1.4.1
14
14
  ---
15
15
 
16
16
  **Boundary.** `auth` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build.
@@ -338,13 +338,13 @@ Say "check your email" after `requestPasswordReset` either way, and never branch
338
338
  ```ts
339
339
  const signOut = createServerFn({ method: 'POST' }).handler(async () => {
340
340
  await auth.signOut()
341
- throw redirect({ to: '/login' })
341
+ throw redirect({ to: '/login', search: { signedOut: true } })
342
342
  })
343
343
  ```
344
344
 
345
- It returns nothing and has no failure the visitor can act on, so send them somewhere and let the redirect re-resolve the context. It ends every session that visitor has in this app, on every device, so a "sign out of this device only" button is not something you can build on it.
345
+ `signedOut` keeps a login page that sends visitors straight to single sign-on from signing them back in at once: see [references/single-sign-on.md](./references/single-sign-on.md). If the redirect fails the type check with `'signedOut' does not exist`, the app's login route does not declare it yet. Add `signedOut: z.boolean().optional().catch(undefined)` to that route's `validateSearch`. Never remove `signedOut` from the redirect to pass the check.
346
346
 
347
- For Studio's "End session if idle", call `useIdleTimeout()` from `@softr/sdk` once in `RootDocument` in `src/routes/__root.tsx`, next to `useUserTimezone()`. It signs out this browser only and sends the visitor to `/`. Don't build your own idle timer.
347
+ It returns nothing and has no failure the visitor can act on, so send them somewhere and let the redirect re-resolve the context. It ends every session that visitor has in this app, on every device, so a "sign out of this device only" button is not something you can build on it. For Studio's "End session if idle", call `useIdleTimeout()` from `@softr/sdk` once in `RootDocument` in `src/routes/__root.tsx`, next to `useUserTimezone()`. It signs out this browser only and sends the visitor to `/`. Don't build your own idle timer.
348
348
 
349
349
  ### Sign up, in two steps
350
350
 
@@ -3,13 +3,14 @@ name: charts-and-metrics
3
3
  description: >-
4
4
  Aggregate records in a server function: ds.chart with groupBy, metrics, where,
5
5
  orderBy and date buckets for chart rows, ds.metric for one number, and
6
- distinct values for filter controls, scoped to the records the visitor may
7
- read. Use for a chart, a stat tile or any counted, summed or averaged number,
8
- or when a chart comes back wrong. Single records are record-queries.
6
+ distinct values for filter controls, through the query's filter that keeps
7
+ them to the records the visitor may read. Use for a chart, a stat tile or any
8
+ counted, summed or averaged number, or when a chart comes back wrong. Single
9
+ records are record-queries.
9
10
  metadata:
10
11
  type: sub-skill
11
12
  library: softr-sdk
12
- library_version: 1.4.0
13
+ library_version: 1.4.1
13
14
  ---
14
15
 
15
16
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -168,21 +169,26 @@ Each tile and panel is its own request, fired in parallel from one handler.
168
169
 
169
170
  ### Scope a figure like the records behind it
170
171
 
171
- A chart or a metric reads the same records as a list, so it takes the same scope as every read of the table (see [record-queries](../record-queries/SKILL.md#keep-each-visitor-to-their-own-records)). Without it, a "my revenue" tile adds up everyone's sales, and a chart grouped by a person shows the names of people the visitor may not see. Here a rep sees only their own sales, and `usersQuery` is the app's query on the Users table:
172
+ A chart or a metric reads through the `filter` of its query, like `ds.list` (see [record-queries](../record-queries/SKILL.md#keep-each-visitor-to-their-own-records)). So a figure over a filtered query counts only the records its visitor may read. A chart over another query of the same table needs the same filter. Without it, a "my revenue" tile adds up everyone's sales, and a chart grouped by a person shows the names of people the visitor may not see. Here a rep sees only their own sales. `rep` links to Users, and 'Rk2mVx9pQa4Lz7' is the Record ID field of the users table, declared in softr.json under `user.properties`:
172
173
 
173
174
  ```ts
174
- import { auth, ds } from '@softr/sdk/server'
175
-
176
- const myRevenue = createServerFn().handler(async ({ context }) => {
177
- const me = await auth.currentUserRow(context.user, usersQuery, 'email')
178
- if (me === null) return null
179
- const { value } = await ds
180
- .metric(sales, (q) => q.amount.sum)
181
- .where((q) => q.rep.isOneOf([me.id]))
175
+ const mySales = defineQuery({
176
+ id: 'mySales',
177
+ datasourceId: '00000000-0000-0000-0000-000000000000',
178
+ fields: { amount: 'Vk9cXm2pSz6Ld4', closedAt: 'Xp2dLh6vKz9Fa3' },
179
+ filterFields: { rep: 'Gq5wNt8rJy3Hb1' },
180
+ filter: { rep: { isOneOf: ['USER:::Rk2mVx9pQa4Lz7'] } },
181
+ permissions: { userGroupTypes: ['LOGGED_IN_USERS'], customGroups: ['00000000-0000-0000-0000-00000000000c'] },
182
+ })
183
+
184
+ const myRevenue = createServerFn().handler(async () => {
185
+ const { value } = await ds.metric(mySales, (q) => q.amount.sum)
182
186
  return value
183
187
  })
184
188
  ```
185
189
 
190
+ A chart can group, aggregate and `where` only on `fields`, not on `filterFields`. For a visitor who is signed out, or who has no value for the token, the chart has no rows, a count is `0` and every other metric is `null`.
191
+
186
192
  ## Order of calls
187
193
 
188
194
  `groupBy` comes first and exactly once; a chart cannot be awaited before it. `metrics` follows, at most once, or not at all for distinct values. `where` can be chained anywhere, repeatedly, and calling it more than once ands the filters together. `orderBy` sorts by the chart's own keys, group and metric alike, and only sees the keys declared so far, so call it last.
@@ -5,11 +5,13 @@ description: >-
5
5
  context.user in a route's beforeLoad, and context.user inside a server
6
6
  function handler, where Start types it from the app's registered request
7
7
  middleware. Covers the null guest, the generated SoftrUserGroups that narrows
8
- group ids to the app's own, and reading the visitor's role on the server.
8
+ group ids to the app's own, reading the visitor's role on the server, and the
9
+ fields of their row that softr.json declares in user.properties, such as the
10
+ Record ID a filter compares a link to Users with.
9
11
  metadata:
10
12
  type: sub-skill
11
13
  library: softr-sdk
12
- library_version: 1.4.0
14
+ library_version: 1.4.1
13
15
  ---
14
16
 
15
17
  # The current user
@@ -33,6 +35,7 @@ type User = {
33
35
  userGroupIds: Array<SoftrUserGroupId> // the app's own group ids
34
36
  avatarUrl: string | null // their photo; show their initials when null
35
37
  avatarEditable: boolean // whether auth.updateProfile can change the photo
38
+ properties: SoftrUserProperties // the fields softr.json declares under user.properties
36
39
  }
37
40
  ```
38
41
 
@@ -75,39 +78,53 @@ Never pass the visitor's id from a loader into a server function. The loader als
75
78
  ```ts
76
79
  import { createServerFn } from '@tanstack/react-start'
77
80
  import { defineQuery } from '@softr/sdk'
78
- import { auth, ds } from '@softr/sdk/server'
81
+ import { ds } from '@softr/sdk/server'
79
82
 
80
83
  const myInvoices = defineQuery({
81
84
  id: 'myInvoices',
82
85
  // The datasource id from the table's registration on the application — not the table id.
83
86
  datasourceId: '00000000-0000-0000-0000-000000000001',
84
- fields: { owner: 'Gq5wNt8rJy3Hb1', amount: 'Vk9cXm2pSz6Ld4' },
87
+ fields: { amount: 'Vk9cXm2pSz6Ld4' },
88
+ filterFields: { owner: 'Gq5wNt8rJy3Hb1' },
89
+ filter: { owner: { isOneOf: ['USER:::Rk2mVx9pQa4Lz7'] } },
85
90
  permissions: { userGroupTypes: ['LOGGED_IN_USERS'] },
86
91
  })
87
92
 
88
93
  const getMyInvoices = createServerFn().handler(async ({ context }) => {
89
- const me = await auth.currentUserRow(context.user, usersQuery, 'email')
90
- if (me === null) return { records: [], total: 0, nextOffset: null }
91
- return await ds.list(myInvoices).where((q) => q.owner.isOneOf([me.id]))
94
+ if (!context.user) throw new Error('Not signed in')
95
+ return await ds.list(myInvoices)
92
96
  })
93
97
  ```
94
98
 
95
- Here `owner` links to Users, and `usersQuery` is the app's query on the Users table. `auth.currentUserRow` answers `null` when the visitor is signed out or has no row. See [record-queries](../record-queries/SKILL.md#keep-each-visitor-to-their-own-records) for the scope every read of the table takes.
99
+ Here `owner` links to Users, and `USER:::Rk2mVx9pQa4Lz7` is the visitor's value of the Record ID field that `user.properties` declares. The filter needs no lookup of the visitor. See [record-queries](../record-queries/SKILL.md#keep-each-visitor-to-their-own-records) for the filter every query of the table takes.
96
100
 
97
101
  `context.user` is typed. Start derives a handler's context from the app's registered request middleware as well as the server function's own, so there is nothing to import and nothing to cast.
98
102
 
99
103
  ### The visitor's role, in a server function
100
104
 
101
- A server function that answers by role reads the role from `context.user.userGroupIds`, never from an argument. Use it to pick which query and which scope the role reads, as [record-queries](../record-queries/SKILL.md#keep-each-visitor-to-their-own-records) shows:
105
+ A server function that answers by role reads the role from `context.user.userGroupIds`, never from an argument. Use it to pick the query of that role, as [record-queries](../record-queries/SKILL.md#keep-each-visitor-to-their-own-records) shows:
102
106
 
103
107
  ```ts
104
108
  if (!context.user) throw new Error('Not signed in')
105
109
  if (context.user.userGroupIds.includes('00000000-0000-0000-0000-00000000000a')) {
106
- // read with the staff query and the staff scope
110
+ // read with the staff query
107
111
  }
108
112
  ```
109
113
 
110
- `context.user.id` is the visitor's account id, not their row in the Users table. A link to Users holds the row id, so a filter on such a link takes the row that `auth.currentUserRow` finds.
114
+ `context.user.id` is the visitor's account id, not their row in the users table. A link to Users holds the row id, so a filter on such a link compares it with a Record ID field of the users table, declared in `user.properties`.
115
+
116
+ ### Fields of the visitor's row: `user.properties`
117
+
118
+ `softr.json` declares the fields of the users table that the app reads for the visitor, under `user.properties`. Each key is an alias you choose, and each value is a field id of the users table:
119
+
120
+ ```json
121
+ "user": { "properties": { "recordId": "Rk2mVx9pQa4Lz7", "teams": "Tm6cBq1wZe8Ys4" } }
122
+ ```
123
+
124
+ - `context.user.properties.<alias>` and `useCurrentUser()?.properties.<alias>` read the visitor's value, typed as the field reads. `docs/user-properties.md` lists the declared fields, once the declaration is saved.
125
+ - A `filter` compares a field with the visitor's value as `USER:::<field id>`, here `USER:::Rk2mVx9pQa4Lz7`. Only a declared field works there.
126
+ - The visitor's row id is a Record ID field. When the users table has none, add a field of type `RECORD_ID` to it, then declare it. A create sets an owner link from `context.user.properties.recordId` on the server.
127
+ - A field id that the users table does not have throws for every signed-in visitor. Copy the id from the users table's datasource doc.
111
128
 
112
129
  ### Group ids are the app's own
113
130
 
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 1.4.0
10
+ library_version: 1.4.1
11
11
  ---
12
12
 
13
13
  **Boundary.** `upload` lives on `@softr/sdk/server` and runs inside server functions. `useFileUpload` and `FileItem` live on `@softr/sdk` and run in components. `FileAttachment` comes from `@softr/sdk` and can be imported anywhere.
@@ -8,7 +8,7 @@ description: >-
8
8
  metadata:
9
9
  type: sub-skill
10
10
  library: softr-sdk
11
- library_version: 1.4.0
11
+ library_version: 1.4.1
12
12
  ---
13
13
 
14
14
  # Dates, times and numbers
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 1.4.0
10
+ library_version: 1.4.1
11
11
  ---
12
12
 
13
13
  **Boundary.** `integration` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineIntegration` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.4.0
12
+ library_version: 1.4.1
13
13
  ---
14
14
 
15
15
  **Boundary.** `softrMcpMiddleware` lives on `@softr/sdk` and is registered once, in `src/start.ts`. The actions you hand it are the same `defineQuery` / `defineMutation` values the app's own pages use — declared wherever they already live, not duplicated for MCP.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.4.0
12
+ library_version: 1.4.1
13
13
  ---
14
14
 
15
15
  # Push notifications
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.4.0
12
+ library_version: 1.4.1
13
13
  ---
14
14
 
15
15
  # Installing the app
@@ -3,13 +3,14 @@ name: record-mutations
3
3
  description: >-
4
4
  Create, update and delete records with defineMutation, ds.create, ds.update
5
5
  and ds.delete: the payload keyed by your own field names, what each field type
6
- accepts, and keeping an update or a delete to the records the visitor may
7
- read. Use when submitting a form, saving an edit or deleting a record, or when
8
- a write fails or changes nothing. Reads are record-queries.
6
+ accepts, and the filter that keeps an update or a delete to the records the
7
+ visitor may read, with one mutation per role. Use when submitting a form,
8
+ saving an edit or deleting a record, or when a write fails or changes nothing.
9
+ Reads are record-queries.
9
10
  metadata:
10
11
  type: sub-skill
11
12
  library: softr-sdk
12
- library_version: 1.4.0
13
+ library_version: 1.4.1
13
14
  ---
14
15
 
15
16
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineMutation` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -114,53 +115,55 @@ Resolves to nothing. A record that cannot be deleted throws.
114
115
 
115
116
  ### Change only the records the visitor may read
116
117
 
117
- When a role reads only some records of a table, it updates and deletes only those records. `permissions` decides who may run the mutation, not which record. The id comes from the browser, so it can name any record. Before the write, read the record through the same query and scope as every read of the table (see [record-queries](../record-queries/SKILL.md#keep-each-visitor-to-their-own-records)). When the role changes fewer records than it reads, that read filters on the records it may change instead (see [Only the roles that change a table](#only-the-roles-that-change-a-table)). Refuse the write when that read answers `null`, with the same error as a missing record, so the visitor cannot find out which ids exist. Keep the field that the scope filters on, such as the owner, out of the update's `fields`. If it is in `fields`, a visitor can move a record to another person.
118
-
119
- Below, `bookings` is the query every read of bookings uses, and `usersQuery` is the app's query on the Users table. `updateBooking` declares `status` only, not `client`.
118
+ When a role reads only some records of a table, it updates and deletes only those records. `permissions` decides who may run the mutation, not which record. The id comes from the browser, so it can name any record. Give the update and the delete the same `filter` and `filterFields` as the role's queries (see [record-queries](../record-queries/SKILL.md#keep-each-visitor-to-their-own-records)). A record that the filter excludes throws `datasource update failed for action "<id>": record "<id>" not found`, and nothing is written. A missing record throws the same error, so the visitor cannot find out which ids exist. A create takes no filter: set its owner link on the server, from the Record ID that `context.user.properties` holds (see [current-user](../current-user/SKILL.md#fields-of-the-visitors-row-userproperties)), never from an argument.
120
119
 
121
120
  ```ts
122
- import { auth, ds } from '@softr/sdk/server'
121
+ // The same filter as `myBookings`, the query every client reads bookings with.
122
+ const cancelMyBooking = defineMutation({
123
+ id: 'cancelMyBooking',
124
+ datasourceId: '00000000-0000-0000-0000-000000000002',
125
+ operation: 'update',
126
+ fields: { status: 'Ru7bVx2cNq0Ed9' },
127
+ filterFields: { client: 'Pc8vNm3kTq6Wz2' },
128
+ filter: { client: { isOneOf: ['USER:::Rk2mVx9pQa4Lz7'] } },
129
+ permissions: { userGroupTypes: ['LOGGED_IN_USERS'], customGroups: ['00000000-0000-0000-0000-00000000000c'] },
130
+ })
123
131
 
124
132
  const cancelBooking = createServerFn({ method: 'POST' })
125
133
  .validator(z.object({ id: z.string() }))
126
- .handler(async ({ context, data }) => {
127
- const me = await auth.currentUserRow(context.user, usersQuery, 'email')
128
- if (me === null) throw new Error('Booking not found')
129
- const booking = await ds.get(bookings, { id: data.id }).where((q) => q.client.isOneOf([me.id]))
130
- if (booking === null) throw new Error('Booking not found')
131
- await ds.update(updateBooking, { id: booking.id, data: { status: { id: 'cancelled' } } })
132
- })
134
+ .handler(({ data }) => ds.update(cancelMyBooking, { id: data.id, data: { status: { id: 'cancelled' } } }))
133
135
  ```
134
136
 
135
- A delete takes the same read before `ds.delete`. A create into a table that takes its parent's scope, such as a message in a chat, reads the parent through its scope before `ds.create` (see [record-queries](../record-queries/SKILL.md#a-table-with-no-link-to-users-takes-its-parents-scope)).
137
+ A delete declares `filterFields` and `filter` the same way, with no `fields`.
138
+
139
+ An update cannot write a field that its filter compares with a user token, such as the owner. Otherwise a user could give the record to another user, and `defineMutation` throws when the module loads. Keep that field out of the update's `fields`. When a role must reassign records, such as staff, declare a separate mutation for it, with its own `customGroups` and without that filter.
140
+
141
+ A visitor who is signed out, or a user with no value for the token, changes nothing: the write throws "not found". Show the error as a missing record, with no retry.
142
+
143
+ A create into a table that belongs to the visitor through its parent, such as a message in a chat, reads the parent through its filtered query before `ds.create` (see [record-queries](../record-queries/SKILL.md#a-table-that-belongs-to-the-visitor-through-its-parent)).
136
144
 
137
145
  ### Only the roles that change a table
138
146
 
139
- Often fewer roles change a table than read it. A mutation's `customGroups` names only the roles that may change the table, also when more roles read it. In a barber app, every client reads the free hours, but only barbers open or close them. So the slot update names the barbers' group only:
147
+ Often fewer roles change a table than read it. A mutation's `customGroups` names only the roles that may change the table, also when more roles read it. In a barber app, every client reads the free hours, but only barbers open or close them. A barber also changes only their own slots. The read of slots has no filter, because every client reads every slot, so the update filters on the slot's barber:
140
148
 
141
149
  ```ts
142
- const updateSlot = defineMutation({
143
- id: 'updateSlot',
150
+ // `barber` links to Users. Only barbers run it, and only on their own slots.
151
+ const setMySlotOpen = defineMutation({
152
+ id: 'setMySlotOpen',
144
153
  datasourceId: '00000000-0000-0000-0000-000000000004',
145
154
  operation: 'update',
146
155
  fields: { open: 'Wd5nKp2xRb8Tc3' },
156
+ filterFields: { barber: 'Jf3sLc7nVb1Qx5' },
157
+ filter: { barber: { isOneOf: ['USER:::Rk2mVx9pQa4Lz7'] } },
147
158
  permissions: { userGroupTypes: ['LOGGED_IN_USERS'], customGroups: ['00000000-0000-0000-0000-00000000000b'] },
148
159
  })
149
160
  ```
150
161
 
151
- A barber also changes only their own slots. Every client reads every slot, so the read scope does not stop one barber from changing another barber's hours. When a role changes fewer records than it reads, the read before the write filters on the records it may change. Here `slots` is the query every read of slots uses, and its `barber` field links to Users:
162
+ A write can be narrower than the read, never wider: a role that reads only its own records never writes through a mutation without that filter.
152
163
 
153
- ```ts
154
- const setSlotOpen = createServerFn({ method: 'POST' })
155
- .validator(z.object({ id: z.string(), open: z.boolean() }))
156
- .handler(async ({ context, data }) => {
157
- const me = await auth.currentUserRow(context.user, usersQuery, 'email')
158
- if (me === null) throw new Error('Slot not found')
159
- const slot = await ds.get(slots, { id: data.id }).where((q) => q.barber.isOneOf([me.id]))
160
- if (slot === null) throw new Error('Slot not found')
161
- await ds.update(updateSlot, { id: slot.id, data: { open: data.open } })
162
- })
163
- ```
164
+ ### One mutation per role
165
+
166
+ When roles may write different fields, declare one update per role, each with its own `customGroups`, `fields` and `filter`. Pick the mutation on the server by `context.user.userGroupIds`. A role that may read some records but not change them has no mutation that admits it: its group is in no `customGroups` of an update or a delete.
164
167
 
165
168
  ### Edit an existing record
166
169
 
@@ -2,15 +2,16 @@
2
2
  name: record-queries
3
3
  description: >-
4
4
  Fetch records with defineQuery, ds.list and ds.get: where and orderBy, field
5
- names of your own choosing, pagination and its limits, and keeping each
6
- visitor to their own records and to the fields their role may see. Use to put
7
- records on a page or fill a dropdown, to write any server function that reads
8
- a table, or when a read comes back empty, unsorted or missing a field. Writes
9
- are record-mutations; totals and chart rows are charts-and-metrics.
5
+ names of your own choosing, pagination and its limits, and the filter that
6
+ keeps each visitor to their own records, with one query per role for the
7
+ fields that role may see. Use to put records on a page or fill a dropdown, to
8
+ write any server function that reads a table, or when a read comes back empty,
9
+ unsorted or missing a field. Writes are record-mutations; totals and chart
10
+ rows are charts-and-metrics.
10
11
  metadata:
11
12
  type: sub-skill
12
13
  library: softr-sdk
13
- library_version: 1.4.0
14
+ library_version: 1.4.1
14
15
  ---
15
16
 
16
17
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. The same holds for any helper that calls `ds`: declare it inside the handler. A function at module level that calls `ds` keeps the server-only import in the browser bundle, and every page stops loading until it moves. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -57,7 +58,7 @@ const publishedPosts = defineQuery({
57
58
  - Write each group id as a literal in `permissions`. An id taken from a `const` is a lint error.
58
59
  - Write the object inline in the `defineQuery` call. Passing the declaration or its `fields` through a variable, or spreading one in, widens the field ids to `string` and the types stop checking.
59
60
 
60
- A query fixes the table and the columns, not the rows: filters, sorting and paging stay at the call site, because a list screen changes them as the user types. Declare as many queries over one datasource as the app needs, each carrying the fields its own screen touches.
61
+ A query fixes the table and the columns. A `filter` also fixes the rows a role may read, for a privacy rule that never changes: see [Keep each visitor to their own records](#keep-each-visitor-to-their-own-records). The filters the user picks, sorting and paging stay at the call site, because a list screen changes them as the user types. Declare as many queries over one datasource as the app needs, each carrying the fields its own screen touches.
61
62
 
62
63
  ## Core Patterns
63
64
 
@@ -89,7 +90,7 @@ await ds.list(publishedPosts).where((q) =>
89
90
  )
90
91
  ```
91
92
 
92
- Calling `.where` more than once ands the filters together, which is how a fixed scope and a user-supplied filter combine. Only the query's own fields can be filtered or sorted on, so a field you need in a `where` belongs in `fields` even when the page never displays it. Load [references/filters-and-sorting.md](./references/filters-and-sorting.md) when you need an operator this page does not show, or when a filter is rejected.
93
+ Calling `.where` more than once ands the filters together, and the query's `filter` too, so a `where` only narrows the rows. Only the query's own fields can be filtered or sorted on, so a field you need in a `where` belongs in `fields` even when the page never displays it. Load [references/filters-and-sorting.md](./references/filters-and-sorting.md) when you need an operator this page does not show, or when a filter is rejected.
93
94
 
94
95
  ### Sort
95
96
 
@@ -164,7 +165,7 @@ const loadProductStatuses = createServerFn()
164
165
  .handler(({ data }) => ds.options(productStatuses, { label: 'name', ...data }))
165
166
  ```
166
167
 
167
- `ds.options` takes no `where`, so use it only over a table with no scope. A picker over a scoped table reads with `ds.list` and the scope: see [A picker over a scoped table](#a-picker-over-a-scoped-table).
168
+ `ds.options` takes no `where`, but it reads through the query's `filter`. A picker over a filtered table takes the filtered query.
168
169
 
169
170
  Skip this request when the options are predefined and fixed — hardcode them instead.
170
171
 
@@ -179,110 +180,141 @@ A read the datasource turns down throws rather than coming back empty, and it th
179
180
 
180
181
  ## Keep each visitor to their own records
181
182
 
182
- `permissions` decides who may run a query. It does not decide which rows they get, and it does not hide a field the query declares. A visitor can call every server function with any arguments, so one read that skips a rule opens the table to them. The examples below use `bookings`, a query over a table where a client sees only their own bookings, and `usersQuery`, the app's query on the Users table.
183
+ `permissions` decides who may run a query. `filter` decides which rows it reads. A visitor can call every server function with any arguments, so a privacy rule from the builder's prompt, such as "clients see only their own bookings", goes into the `filter` of the table's queries, never into the code of one server function. `ds` applies the filter on every `ds.list`, `ds.get`, `ds.options`, `ds.chart` and `ds.metric` of the query, and a `where` cannot widen it. Keep `where` for the filters the visitor picks at runtime: a search, a tab, a dropdown.
183
184
 
184
- ### One scope per table, in every read
185
+ The examples below use `bookings`, a table where staff read every booking and a client reads only their own.
185
186
 
186
- A privacy rule from the builder's prompt, such as "clients see only their own bookings", belongs to the table, not to the page where it came up. Every server function that reads the table applies the same `where`: the list, the get by id, a search, a picker, a count and a chart. Keep these server functions beside the table's queries, so the copies of the filter stay together and a new read is written next to them. A get by id takes the same `where`, so an id outside the scope reads as `null`.
187
+ ### Declare the filter
187
188
 
188
189
  ```ts
189
- // Bookings are private: a client reads only the bookings linked to their own Users row.
190
- // Every read of bookings applies this filter.
190
+ // `client` links to Users. 'Rk2mVx9pQa4Lz7' is the Record ID field of the users table,
191
+ // declared in softr.json under user.properties.
192
+ const myBookings = defineQuery({
193
+ id: 'myBookings',
194
+ datasourceId: '00000000-0000-0000-0000-000000000002',
195
+ fields: { title: 'Lb7yQe3vXa9Ns1', date: 'Xp2dLh6vKz9Fa3', status: 'Ru7bVx2cNq0Ed9' },
196
+ filterFields: { client: 'Pc8vNm3kTq6Wz2' },
197
+ filter: { client: { isOneOf: ['USER:::Rk2mVx9pQa4Lz7'] } },
198
+ permissions: { userGroupTypes: ['LOGGED_IN_USERS'], customGroups: ['00000000-0000-0000-0000-00000000000c'] },
199
+ })
200
+
191
201
  const getMyBooking = createServerFn()
192
202
  .validator(z.object({ id: z.string() }))
193
- .handler(async ({ context, data }) => {
194
- const me = await auth.currentUserRow(context.user, usersQuery, 'email')
195
- if (me === null) return null
196
- return await ds.get(bookings, { id: data.id }).where((q) => q.client.isOneOf([me.id]))
197
- })
203
+ .handler(({ data }) => ds.get(myBookings, { id: data.id }))
198
204
  ```
199
205
 
200
- The filter matches the field that holds the owner. A link to the Users table holds the visitor's row there, not `context.user.id`. `auth.currentUserRow(context.user, usersQuery, 'email')` finds that row by email, or answers `null` when they are signed out or have no row. See [current-user](../current-user/SKILL.md) for how the visitor gets onto `context`.
206
+ - The keys of `filter` are aliases of `filterFields`, with the same operators as `where`. Declare the two together. A read returns only `fields`, so a field that only the filter needs, such as the owner, never reaches the browser. A field that the page shows and the filter reads goes in both. A `where` names aliases of `fields` only.
207
+ - The keys of one object combine with AND. `$and` and `$or` take a list of filters. A filter has at most 4 group levels.
208
+ - A get of an id that the filter excludes reads as `null`, the same as a missing record.
209
+ - Write the filter inline, as literals, like the rest of the declaration.
210
+
211
+ Write a token in the form the Studio condition builder stores:
212
+
213
+ | Token | Value |
214
+ | --- | --- |
215
+ | `{USER:::EMAIL}`, `{USER:::EMAIL_DOMAIN}` | The visitor's email, and its domain. With braces |
216
+ | `USER:::<field id>` | A field of the visitor's row in the users table, declared in `user.properties`. No braces |
217
+ | `PREDEFINED:TODAY`, `PREDEFINED:YESTERDAY`, `PREDEFINED:TOMORROW` | That day |
218
+ | `FIXED_DATE:DAYS_AGO:<n>`, `FIXED_DATE:DAYS_FROM_NOW:<n>` | A day relative to today |
219
+
220
+ There are no other tokens: a value from the URL, the page or a form goes into a `where`. A filter can only compare a field of this table: it cannot follow a link to the owner of another table (see [A table that belongs to the visitor through its parent](#a-table-that-belongs-to-the-visitor-through-its-parent)).
221
+
222
+ ### A link to Users
223
+
224
+ A link to the users table holds the id of the visitor's row in that table, not `context.user.id`. Compare it with a Record ID field of the users table:
201
225
 
202
- ### A picker over a scoped table
226
+ 1. Find a `RECORD_ID` field in the users table's datasource doc. When the table has none, add a field of type `RECORD_ID` to it.
227
+ 2. Declare that field in `softr.json` under `user.properties`. The key is an alias you choose, and the value is the field id:
203
228
 
204
- `ds.options` takes no `where`, so a picker over a scoped table reads with `ds.list` and the scope, and maps the records to the `{ id, label }` the picker takes. Here `title` is the field of `bookings` the picker shows:
229
+ ```json
230
+ "user": { "properties": { "recordId": "Rk2mVx9pQa4Lz7" } }
231
+ ```
232
+
233
+ 3. Compare the link with `USER:::<that field id>`, here `USER:::Rk2mVx9pQa4Lz7`.
234
+
235
+ A token on a field that `user.properties` does not declare throws. An email field that holds the owner's email compares with `{USER:::EMAIL}` and needs no declaration. See [current-user](../current-user/SKILL.md#fields-of-the-visitors-row-userproperties) for `user.properties`.
236
+
237
+ ### A field that holds several values
238
+
239
+ Compare a field of the visitor that can hold several values, such as a link to their teams, with `isOneOf`. With `is`, a visitor in two teams reads no rows.
205
240
 
206
241
  ```ts
207
- const loadMyBookings = createServerFn()
208
- .validator(z.object({ term: z.string(), offset: z.number().nullable() }))
209
- .handler(async ({ context, data }) => {
210
- const me = await auth.currentUserRow(context.user, usersQuery, 'email')
211
- if (me === null) return { options: [], nextOffset: null }
212
- const term = data.term.trim()
213
- let list = ds.list(bookings).where((q) => q.client.isOneOf([me.id]))
214
- if (term !== '') list = list.where((q) => q.title.contains(term))
215
- const page = await list.offset(data.offset).limit(20)
216
- return {
217
- options: page.records.map((record) => ({ id: record.id, label: record.fields.title ?? '' })),
218
- nextOffset: page.nextOffset,
219
- }
220
- })
242
+ // 'Tm6cBq1wZe8Ys4' is the teams link of the users table, declared in user.properties.
243
+ filter: { team: { isOneOf: ['USER:::Tm6cBq1wZe8Ys4'] } }
221
244
  ```
222
245
 
223
- ### Server functions you add use the same scope
246
+ A field of the record that holds several values takes `isOneOf` too: `members: { isOneOf: ['USER:::Rk2mVx9pQa4Lz7'] }` keeps the projects the visitor is a member of.
224
247
 
225
- A server function you write for a new page or widget applies the table's scope too. When it needs other fields, it may declare its own query over the table, but every query over a scoped table takes the same scope. A query read without it is a second path to the same rows.
248
+ ### Signed out, or no value
249
+
250
+ A condition on a user token matches no rows for a visitor who is signed out, or for a user whose field is empty, such as a user in no team. The read answers an empty list, and a get answers `null`. In an `$or`, the other branches still match:
226
251
 
227
252
  ```ts
253
+ // `ownerEmail` is in filterFields only, so public rows do not show it.
254
+ filter: { $or: [{ ownerEmail: { is: '{USER:::EMAIL}' } }, { visibility: { is: 'public' } }] }
255
+ ```
256
+
257
+ ### Every query over the table takes the filter
258
+
259
+ A privacy rule belongs to the table, not to the page where it came up. Every query that a role reads the table with carries the same `filter`: the list, the detail, a search, a picker, a count and a chart. This includes a query you add later for a new page or widget. A query without the filter is a second path to the same rows. Reuse the table's queries where you can. A new query with other fields copies `filter` and `filterFields`:
260
+
261
+ ```ts
262
+ // Wrong: no filter. Every client reads every booking through this query.
228
263
  const nextBookings = defineQuery({
229
264
  id: 'nextBookings',
230
265
  datasourceId: '00000000-0000-0000-0000-000000000002',
231
- fields: { date: 'Xp2dLh6vKz9Fa3', client: 'Pc8vNm3kTq6Wz2' },
232
- permissions: { userGroupTypes: ['LOGGED_IN_USERS'] },
266
+ fields: { date: 'Xp2dLh6vKz9Fa3' },
267
+ permissions: { userGroupTypes: ['LOGGED_IN_USERS'], customGroups: ['00000000-0000-0000-0000-00000000000c'] },
233
268
  })
234
269
 
235
- // Wrong: read with no scope. Every client sees every booking.
236
- const loadNext = createServerFn().handler(() => ds.list(nextBookings).limit(3))
237
-
238
- // Right: the same scope as every other read of bookings.
239
- const loadNext = createServerFn().handler(async ({ context }) => {
240
- const me = await auth.currentUserRow(context.user, usersQuery, 'email')
241
- if (me === null) return { records: [], total: 0, nextOffset: null }
242
- return await ds
243
- .list(nextBookings)
244
- .where((q) => q.client.isOneOf([me.id]))
245
- .orderBy((q) => q.date.asc)
246
- .limit(3)
270
+ // Right: the same filter as every other query of bookings for clients.
271
+ const nextBookings = defineQuery({
272
+ id: 'nextBookings',
273
+ datasourceId: '00000000-0000-0000-0000-000000000002',
274
+ fields: { date: 'Xp2dLh6vKz9Fa3' },
275
+ filterFields: { client: 'Pc8vNm3kTq6Wz2' },
276
+ filter: { client: { isOneOf: ['USER:::Rk2mVx9pQa4Lz7'] } },
277
+ permissions: { userGroupTypes: ['LOGGED_IN_USERS'], customGroups: ['00000000-0000-0000-0000-00000000000c'] },
247
278
  })
279
+
280
+ const loadNext = createServerFn().handler(() =>
281
+ ds.list(nextBookings).where((q) => q.date.gte(new Date().toISOString())).orderBy((q) => q.date.asc).limit(3),
282
+ )
248
283
  ```
249
284
 
250
- The scope filters on `client`, so `nextBookings` declares it, also when the page does not show it.
285
+ The update and the delete of these records take the same filter: see [record-mutations](../record-mutations/SKILL.md#change-only-the-records-the-visitor-may-read). A count or a chart reads through the filter of its query: see [charts-and-metrics](../charts-and-metrics/SKILL.md).
251
286
 
252
- ### A table with no link to Users takes its parent's scope
287
+ ### One query per role
253
288
 
254
- Some tables have no link to Users. Chat messages belong to a chat, and the browser sends the chat id. If a server function reads the messages by that id alone, any chat id reads its messages. The same goes for a game room read by its code. Such a table takes its parent's scope: read the parent through its own scope first. Read or post the children only when that read answers, and filter them on the parent that it answered. Here `chats` has a `members` link to Users, and `messages` has a `chat` link to chats:
289
+ When roles read a table by different rules, or see different fields of it, declare one query per role. Each one has its own `customGroups`, `fields` and `filter`. A filtered query names the groups of its role in `customGroups`, never every signed-in user. Only when one rule holds for every signed-in user, keep `LOGGED_IN_USERS` with no groups. Pick the query on the server by the visitor's groups, never by an argument:
255
290
 
256
291
  ```ts
257
- const listMessages = createServerFn()
258
- .validator(z.object({ chatId: z.string() }))
259
- .handler(async ({ context, data }) => {
260
- const me = await auth.currentUserRow(context.user, usersQuery, 'email')
261
- if (me === null) throw new Error('Chat not found')
262
- const chat = await ds.get(chats, { id: data.chatId }).where((q) => q.members.isOneOf([me.id]))
263
- if (chat === null) throw new Error('Chat not found')
264
- return await ds
265
- .list(messages)
266
- .where((q) => q.chat.isOneOf([chat.id]))
267
- .orderBy((q) => q.sentAt.desc)
268
- .limit(100)
269
- })
270
- ```
271
-
272
- The read sorts newest first, so the limit keeps the newest 100 messages. Reverse them in the page to show the oldest on top.
292
+ const bookingsForStaff = defineQuery({
293
+ id: 'bookingsForStaff',
294
+ datasourceId: '00000000-0000-0000-0000-000000000002',
295
+ fields: { title: 'Lb7yQe3vXa9Ns1', date: 'Xp2dLh6vKz9Fa3', status: 'Ru7bVx2cNq0Ed9', client: 'Pc8vNm3kTq6Wz2' },
296
+ permissions: { userGroupTypes: ['LOGGED_IN_USERS'], customGroups: ['00000000-0000-0000-0000-00000000000a'] },
297
+ })
273
298
 
274
- A server function that posts a message reads the chat the same way before `ds.create`.
299
+ const listBookings = createServerFn().handler(async ({ context }) => {
300
+ if (!context.user) throw new Error('Not signed in')
301
+ if (context.user.userGroupIds.includes('00000000-0000-0000-0000-00000000000a')) {
302
+ return await ds.list(bookingsForStaff).limit(50)
303
+ }
304
+ return await ds.list(myBookings).limit(50)
305
+ })
306
+ ```
275
307
 
276
- ### Other people's records show only what the role needs
308
+ `bookingsForStaff` has no filter: staff read every booking. Its `customGroups` names staff only, so a client cannot run it.
277
309
 
278
- A read returns every field its query declares, and everything a server function returns reaches the browser, also when the page does not show it. A list of other people, such as a directory or the members of a chat, declares only the fields its role needs, so no email or phone unless the role needs them. A `USER` field reads back with the person's email, so a list that must not show emails does not declare one either. When roles need different fields, declare one query per role, each with its own `fields` and `permissions`, and pick the query on the server by the visitor's groups:
310
+ A list of other people, such as a directory or the members of a chat, declares only the fields its role needs: no email or phone unless the role needs them. Everything a server function returns reaches the browser, also when the page does not show it. A `USER` field reads back with the person's email, so a list that must not show emails does not declare one either. Here members see names and job titles, and staff see emails too:
279
311
 
280
312
  ```ts
281
313
  const peopleForMembers = defineQuery({
282
314
  id: 'peopleForMembers',
283
315
  datasourceId: '00000000-0000-0000-0000-000000000003',
284
316
  fields: { name: 'Hn4tRw8kPz2Mc5', jobTitle: 'Lb7yQe3vXa9Ns1' },
285
- permissions: { userGroupTypes: ['LOGGED_IN_USERS'] },
317
+ permissions: { userGroupTypes: ['LOGGED_IN_USERS'], customGroups: ['00000000-0000-0000-0000-00000000000c'] },
286
318
  })
287
319
 
288
320
  const peopleForStaff = defineQuery({
@@ -291,17 +323,29 @@ const peopleForStaff = defineQuery({
291
323
  fields: { name: 'Hn4tRw8kPz2Mc5', jobTitle: 'Lb7yQe3vXa9Ns1', email: 'Td2kWm6pFs8Jq4' },
292
324
  permissions: { userGroupTypes: ['LOGGED_IN_USERS'], customGroups: ['00000000-0000-0000-0000-00000000000a'] },
293
325
  })
326
+ ```
294
327
 
295
- const listPeople = createServerFn().handler(async ({ context }) => {
296
- if (!context.user) throw new Error('Not signed in')
297
- if (context.user.userGroupIds.includes('00000000-0000-0000-0000-00000000000a')) {
298
- return await ds.list(peopleForStaff).limit(100)
299
- }
300
- return await ds.list(peopleForMembers).limit(100)
301
- })
328
+ ### A table that belongs to the visitor through its parent
329
+
330
+ Some tables have no field to compare with the visitor. Chat messages belong to a chat, and only the chat links to its members. A filter on messages cannot say "the messages of my chats", because it cannot follow the link to the chat's members. The same goes for the players of a game room. Only for such a table, read the parent first through its filtered query. Read or post the children only when that read answers, and filter them on the parent that it answered. Here `myChats` filters chats with `members: { isOneOf: ['USER:::Rk2mVx9pQa4Lz7'] }`, and `messages` has a `chat` link to chats:
331
+
332
+ ```ts
333
+ const listMessages = createServerFn()
334
+ .validator(z.object({ chatId: z.string() }))
335
+ .handler(async ({ data }) => {
336
+ const chat = await ds.get(myChats, { id: data.chatId })
337
+ if (chat === null) throw new Error('Chat not found')
338
+ return await ds
339
+ .list(messages)
340
+ .where((q) => q.chat.isOneOf([chat.id]))
341
+ .orderBy((q) => q.sentAt.desc)
342
+ .limit(100)
343
+ })
302
344
  ```
303
345
 
304
- A role that may change only some rows changes only the rows it can read: see [record-mutations](../record-mutations/SKILL.md). A count or a chart over the table takes the same scope: see [charts-and-metrics](../charts-and-metrics/SKILL.md).
346
+ Every server function that reads or posts messages reads the chat this way first. The read sorts newest first, so the limit keeps the newest 100 messages. Reverse them in the page to show the oldest on top.
347
+
348
+ Use this step only when the rule is about the parent. When it is about the row's own owner, such as "a user sees only the requests they sent", the table filters its own link to Users.
305
349
 
306
350
  ## Typing
307
351
 
@@ -311,7 +355,7 @@ Queries you write are type safe and a type error is shown when there's a mistake
311
355
 
312
356
  - [references/filters-and-sorting.md](./references/filters-and-sorting.md): every filter operator by field type, group nesting and the sort handles. Load it when the operator you want is not in this file, or when a filter is rejected.
313
357
  - [references/field-types.md](./references/field-types.md): the value shape every Softr field type reads back as. Load it when rendering a field whose shape you are unsure of, or when a value is not the string you expected.
314
- - [current-user/SKILL.md](../current-user/SKILL.md): reading the visitor off `context` to scope a query
358
+ - [current-user/SKILL.md](../current-user/SKILL.md): reading the visitor off `context`, and the `user.properties` a filter compares with
315
359
  - [routes-and-visibility/SKILL.md](../routes-and-visibility/SKILL.md): deciding who sees the page the records land on
316
360
  - [charts-and-metrics/SKILL.md](../charts-and-metrics/SKILL.md): aggregating records instead of listing them
317
361
  - [record-mutations/SKILL.md](../record-mutations/SKILL.md): creating, updating and deleting them
@@ -145,3 +145,14 @@ Each field carries `.asc` and `.desc` handles and nothing else. An array applies
145
145
  | `a filter must come from the callback a read hands you` | A `where` value built as a plain object |
146
146
  | `a sort must come from the callback a read hands you` | An `orderBy` value not from the callback's `.asc` / `.desc` handles |
147
147
  | A `TypeError` reading an operator off `undefined` | Filtering or sorting on a field the query does not declare |
148
+
149
+ A `filter` in `defineQuery` or `defineMutation` is checked when the declaration runs, so a wrong one throws as soon as its module loads:
150
+
151
+ | Message | Cause |
152
+ | --- | --- |
153
+ | `declare filter and filterFields together` | One of the two is missing |
154
+ | `the filter names "<alias>", which is not one of filterFields` | A key of the filter is not an alias of `filterFields`, such as an alias of `fields` only |
155
+ | `"<token>" on "<alias>" is not a known token` | A typo in a token, or braces around `USER:::<field id>` |
156
+ | `"<token>" on "<alias>" names a field that softr.json does not declare under user.properties` | The field of the users table is missing from `user.properties` |
157
+ | `the filter has <n> group levels, and Studio shows at most 4` | Too many nested `$and` and `$or`. The root object is level 1 |
158
+ | `defineMutation "<id>": "<alias>" in fields writes <field id>, and the filter compares that field with "<token>"` | An update can write the field that its filter compares with the visitor, such as the owner. See record-mutations |
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.4.0
12
+ library_version: 1.4.1
13
13
  ---
14
14
 
15
15
  **Boundary.** `Audience` and `defineVisibility` come from `@softr/sdk` and work anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.4.0
12
+ library_version: 1.4.1
13
13
  ---
14
14
 
15
15
  **Boundary.** `definePage`, `pageHead`, the access functions and the error predicates come from `@softr/sdk` and work anywhere.
@@ -73,7 +73,7 @@ Everyone is both audiences, as in the first line above. A set names each audienc
73
73
 
74
74
  Take every id in `customGroups` from `docs/user-groups.md`, which lists each group the app has with its name and id. An id the app does not have is a type error.
75
75
 
76
- **`visibility` guards the page, not the server functions it calls.** A call can reach them without the page and with any arguments, so the queries and mutations behind a page carry its groups in their own `permissions`. `permissions` decide who may run them, not which rows they reach: each server function filters the rows itself, as [record-queries](../record-queries/SKILL.md#keep-each-visitor-to-their-own-records) shows.
76
+ **`visibility` guards the page, not the server functions it calls.** A call can reach them without the page and with any arguments, so the queries and mutations behind a page carry its groups in their own `permissions`. `permissions` decide who may run them, not which rows they reach: the `filter` of each query and mutation decides that, as [record-queries](../record-queries/SKILL.md#keep-each-visitor-to-their-own-records) shows.
77
77
 
78
78
  ## Core Patterns
79
79
 
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.4.0
12
+ library_version: 1.4.1
13
13
  ---
14
14
 
15
15
  **Boundary.** `workflow` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineWorkflow` and every type come from `@softr/sdk` and can be imported anywhere.