@softr/sdk 1.10.0 → 1.11.0
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 +7 -0
- package/dist/core/options.js +1 -1
- package/dist/datasource/record.d.ts +8 -2
- package/dist/datasource/record.js +7 -2
- package/dist/mcp.js +3 -2
- package/dist/package.js +1 -1
- package/package.json +1 -1
- package/skills/softr-sdk/SKILL.md +1 -1
- package/skills/softr-sdk/ai/SKILL.md +1 -1
- package/skills/softr-sdk/auth/SKILL.md +1 -1
- package/skills/softr-sdk/charts-and-metrics/SKILL.md +1 -1
- package/skills/softr-sdk/current-user/SKILL.md +1 -1
- package/skills/softr-sdk/email/SKILL.md +1 -1
- package/skills/softr-sdk/file-uploads/SKILL.md +1 -1
- package/skills/softr-sdk/formatting/SKILL.md +1 -1
- package/skills/softr-sdk/integrations/SKILL.md +1 -1
- package/skills/softr-sdk/mcp/SKILL.md +1 -1
- package/skills/softr-sdk/push-notifications/SKILL.md +1 -1
- package/skills/softr-sdk/pwa/SKILL.md +1 -1
- package/skills/softr-sdk/record-mutations/SKILL.md +1 -1
- package/skills/softr-sdk/record-queries/SKILL.md +3 -1
- package/skills/softr-sdk/record-queries/references/filters-and-sorting.md +1 -1
- package/skills/softr-sdk/region-visibility/SKILL.md +1 -1
- package/skills/softr-sdk/routes-and-visibility/SKILL.md +1 -1
- package/skills/softr-sdk/workflows/SKILL.md +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @softr/sdk
|
|
2
2
|
|
|
3
|
+
## 1.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- `ds.list` pages a datasource that answers its own cursor instead of a row position (BigQuery). `nextOffset` is now `number | string | null`: a cursor comes back as the string the datasource answered, where it was `null` before, and `offset()` takes it back unchanged. A numeric offset is still a number. A cursor on a page with no records comes back as `null`, so a loop that reads all pages always stops. `ds.options` keeps paging by row position only.
|
|
8
|
+
- The MCP list tool takes a string `offset`, so a cursor from `nextOffset` reads the next page.
|
|
9
|
+
|
|
3
10
|
## 1.10.0
|
|
4
11
|
|
|
5
12
|
### Minor Changes
|
package/dist/core/options.js
CHANGED
|
@@ -50,7 +50,7 @@ async function listOptions(query, { label, term = "", offset = null, limit = 20
|
|
|
50
50
|
id: record.id,
|
|
51
51
|
label: labelOf(record.fields[label])
|
|
52
52
|
})),
|
|
53
|
-
nextOffset: page.nextOffset
|
|
53
|
+
nextOffset: typeof page.nextOffset === "number" ? page.nextOffset : null
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
@@ -35,11 +35,16 @@ type ListBuilder<TShape extends ReadShape> = {
|
|
|
35
35
|
* Where the page starts. Pass the `nextOffset` of a previous result, or `null` to start
|
|
36
36
|
* over. A result with `nextOffset: null` is the last page.
|
|
37
37
|
*
|
|
38
|
+
* A `nextOffset` that is a number is a row position, so a page can also be reached by its
|
|
39
|
+
* computed position. A `nextOffset` that is a string is the datasource's own cursor (BigQuery
|
|
40
|
+
* answers one): it only reads the page after the one that answered it, with the same `where`
|
|
41
|
+
* and `orderBy`, and a computed number is refused.
|
|
42
|
+
*
|
|
38
43
|
* @example
|
|
39
44
|
* const first = await ds.list(posts).limit(50)
|
|
40
45
|
* const second = await ds.list(posts).limit(50).offset(first.nextOffset)
|
|
41
46
|
*/
|
|
42
|
-
offset(offset: number | null): ListBuilder<TShape>;
|
|
47
|
+
offset(offset: number | string | null): ListBuilder<TShape>;
|
|
43
48
|
} & Promise<ListResult<SoftrRecord<ActionRecord<TShape>>>>;
|
|
44
49
|
/**
|
|
45
50
|
* One record, fetched when awaited. There is no `orderBy`, `limit` or `offset`. The record is
|
|
@@ -67,7 +72,8 @@ interface SoftrRecord<TFields extends Record<string, unknown> = Record<string, u
|
|
|
67
72
|
interface ListResult<TRecord extends SoftrRecord = SoftrRecord> {
|
|
68
73
|
records: TRecord[];
|
|
69
74
|
total: number;
|
|
70
|
-
|
|
75
|
+
/** A row position, or the datasource's own cursor as a string. `null` on the last page. */
|
|
76
|
+
nextOffset: number | string | null;
|
|
71
77
|
}
|
|
72
78
|
type GetRecord<TShape extends ReadShape> = SoftrRecord<ActionRecord<TShape>> | null;
|
|
73
79
|
/**
|
|
@@ -119,8 +119,13 @@ async function executeList(query, args) {
|
|
|
119
119
|
});
|
|
120
120
|
if (!res.ok) throw new Error(`datasource list failed for "${actionId}": ${await describeFailure(res)}`);
|
|
121
121
|
const payload = await res.json();
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
let nextOffset = null;
|
|
123
|
+
if (typeof payload.offset === "string" && !/^\d*$/.test(payload.offset)) {
|
|
124
|
+
if (payload.items.length > 0) nextOffset = payload.offset;
|
|
125
|
+
} else if (payload.offset != null && payload.offset !== "") {
|
|
126
|
+
const rowOffset = Number(payload.offset);
|
|
127
|
+
if (rowOffset < payload.total) nextOffset = rowOffset;
|
|
128
|
+
}
|
|
124
129
|
return {
|
|
125
130
|
records: payload.items.map((item) => ({
|
|
126
131
|
id: item.id,
|
package/dist/mcp.js
CHANGED
|
@@ -287,9 +287,9 @@ function describeTool(action) {
|
|
|
287
287
|
description: `How many records to return. Defaults to ${DEFAULT_LIMIT}.`
|
|
288
288
|
},
|
|
289
289
|
offset: {
|
|
290
|
-
type: "integer",
|
|
290
|
+
type: ["integer", "string"],
|
|
291
291
|
minimum: 0,
|
|
292
|
-
description: "Where the page starts. Use nextOffset from a previous call."
|
|
292
|
+
description: "Where the page starts. Use nextOffset from a previous call, unchanged: a number is a row position, a string is the datasource's own cursor."
|
|
293
293
|
}
|
|
294
294
|
},
|
|
295
295
|
additionalProperties: false
|
|
@@ -389,6 +389,7 @@ function clampLimit(raw) {
|
|
|
389
389
|
return Math.min(Math.max(raw, 1), MAX_LIMIT);
|
|
390
390
|
}
|
|
391
391
|
function clampOffset(raw) {
|
|
392
|
+
if (typeof raw === "string" && raw !== "") return raw;
|
|
392
393
|
if (typeof raw !== "number" || !Number.isInteger(raw) || raw < 0) return null;
|
|
393
394
|
return raw;
|
|
394
395
|
}
|
package/dist/package.js
CHANGED
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@ description: >-
|
|
|
13
13
|
metadata:
|
|
14
14
|
type: sub-skill
|
|
15
15
|
library: softr-sdk
|
|
16
|
-
library_version: 1.
|
|
16
|
+
library_version: 1.11.0
|
|
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.
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.
|
|
13
|
+
library_version: 1.11.0
|
|
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.
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.
|
|
13
|
+
library_version: 1.11.0
|
|
14
14
|
---
|
|
15
15
|
|
|
16
16
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. A helper that calls `ds` outside a handler goes in `createServerOnlyFn` from `@tanstack/react-start` (the `record-queries` boundary). `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -12,7 +12,7 @@ description: >-
|
|
|
12
12
|
metadata:
|
|
13
13
|
type: sub-skill
|
|
14
14
|
library: softr-sdk
|
|
15
|
-
library_version: 1.
|
|
15
|
+
library_version: 1.11.0
|
|
16
16
|
---
|
|
17
17
|
|
|
18
18
|
**Boundary.** `email` and `EmailError` live on `@softr/sdk/server` and run only inside a `createServerFn` handler — importing them into a component fails the build. `defineEmailAction` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 1.
|
|
10
|
+
library_version: 1.11.0
|
|
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.
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 1.
|
|
10
|
+
library_version: 1.11.0
|
|
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.
|
|
12
|
+
library_version: 1.11.0
|
|
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.
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.
|
|
13
|
+
library_version: 1.11.0
|
|
14
14
|
---
|
|
15
15
|
|
|
16
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.
|
|
@@ -11,7 +11,7 @@ description: >-
|
|
|
11
11
|
metadata:
|
|
12
12
|
type: sub-skill
|
|
13
13
|
library: softr-sdk
|
|
14
|
-
library_version: 1.
|
|
14
|
+
library_version: 1.11.0
|
|
15
15
|
---
|
|
16
16
|
|
|
17
17
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. A route `loader` also runs in the browser, so it calls a server function, never `ds`. A helper that calls `ds` outside a handler, in this file or in another one, goes in `createServerOnlyFn` from `@tanstack/react-start`, or inside the handler. An exported helper without it keeps the server-only import in the browser bundle, and every page stops loading until it moves. Do not make such a helper a server function when it takes an id: any visitor can call a server function with any id. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -127,6 +127,8 @@ if (first.nextOffset !== null) {
|
|
|
127
127
|
|
|
128
128
|
`nextOffset` is `null` when there are no more pages. `total` is the count of all matching records, not the count returned.
|
|
129
129
|
|
|
130
|
+
Pass `nextOffset` back unchanged, and type whatever carries it (a validator, a state, a search param) as `number | string | null`. Most datasources answer a number, the row position, and for those a page can also be reached directly, `.offset((page - 1) * PAGE_SIZE)`. Some datasources (BigQuery is one) answer a string, their own cursor: it reads only the page after the one that answered it, with the same `where` and `orderBy`, and a read with a computed number fails. For those, build "Load more" or next-page paging from `nextOffset`, never numbered pages.
|
|
131
|
+
|
|
130
132
|
### Populate a control from a linked table
|
|
131
133
|
|
|
132
134
|
A `LINKED_RECORD` field on a record answers with `{ id, label }` — the label is the linked record's primary field, and the id is what a write or a `where` filter takes. To fill a filter dropdown or form select with **all** options from the linked table (not just the values already referenced by existing records), query the linked table's own datasource:
|
|
@@ -16,7 +16,7 @@ await ds
|
|
|
16
16
|
.where((q) => q.status.is('active')) // one filter, or a $and/$or of filters
|
|
17
17
|
.orderBy((q) => q.title.asc) // or an array of handles
|
|
18
18
|
.limit(20) // default 20, clamped to 100
|
|
19
|
-
.offset(null) // a previous result's nextOffset
|
|
19
|
+
.offset(null) // a previous result's nextOffset, unchanged (number or string)
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
A `where` callback returns exactly one value. For more than one condition, wrap them in `q.$and(...)` or `q.$or(...)`, or call `.where` again: repeated calls are anded.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 1.
|
|
12
|
+
library_version: 1.11.0
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `definePage`, `pageHead`, the access functions and the error predicates 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.
|
|
12
|
+
library_version: 1.11.0
|
|
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.
|