convex-helpers 0.1.133 → 0.1.135
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 +13 -0
- package/README.md +54 -0
- package/dist/bin.cjs +3814 -4183
- package/dist/server/cors.d.ts +17 -1
- package/dist/server/cors.d.ts.map +1 -1
- package/dist/server/cors.js +2 -7
- package/dist/server/cors.js.map +1 -1
- package/dist/server/stream.d.ts.map +1 -1
- package/dist/server/stream.js +4 -4
- package/dist/server/stream.js.map +1 -1
- package/package.json +8 -11
- package/packages/convex-helpers/cli/openApiSpec.ts +30 -9
- package/packages/convex-helpers/server/cors.ts +26 -3
- package/packages/convex-helpers/server/stream.ts +8 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.135
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix `SingletonStream` pagination with open or prefix bounds, and preserve bandwidth accounting and equality filters when narrowing a stream ([#1011](https://github.com/convex/convex-helpers/issues/1011)). [#1069](https://github.com/convex/convex-helpers/pull/1069)
|
|
8
|
+
|
|
9
|
+
## 0.1.134
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- `open-api-spec` renders unions as `anyOf`, so a value matching more than one member
|
|
14
|
+
validates. It also supports `v.bytes()` instead of aborting with "bytes unsupported".
|
|
15
|
+
|
|
3
16
|
## 0.1.133
|
|
4
17
|
|
|
5
18
|
- Zod 4 support: when a `z.object()` schema is passed as `args` to
|
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ Table of contents:
|
|
|
32
32
|
- [Example 2: Paginate all messages whose authors match a complex predicate.](#example-2-paginate-all-messages-whose-authors-match-a-complex-predicate)
|
|
33
33
|
- [Example 3: Order by a suffix of an index.](#example-3-order-by-a-suffix-of-an-index)
|
|
34
34
|
- [Example 4: Join tables.](#example-4-join-tables)
|
|
35
|
+
- [Example 5: Append or prepend a row to each group.](#example-5-append-or-prepend-a-row-to-each-group)
|
|
35
36
|
- [Query Caching](#query-caching)
|
|
36
37
|
- [TypeScript API Generation](#typescript-api-generation)
|
|
37
38
|
- [Open API Spec Generation](#open-api-spec-generation)
|
|
@@ -974,6 +975,57 @@ export const latestMessages = query({
|
|
|
974
975
|
});
|
|
975
976
|
```
|
|
976
977
|
|
|
978
|
+
### Example 5: Append or prepend a row to each group.
|
|
979
|
+
|
|
980
|
+
Suppose you want to combine accounts and projects into a paginated list of
|
|
981
|
+
`{ account, project }` pairs, grouped by account. Append a
|
|
982
|
+
`{ account, project: null }` row to mark the end of each group and include accounts
|
|
983
|
+
with no projects.
|
|
984
|
+
|
|
985
|
+
Inside an existing query handler, with an authenticated `userId` and
|
|
986
|
+
`paginationOpts`, use `flatMap` to merge each account's projects with a
|
|
987
|
+
`SingletonStream`:
|
|
988
|
+
|
|
989
|
+
```ts
|
|
990
|
+
import {
|
|
991
|
+
mergedStream,
|
|
992
|
+
SingletonStream,
|
|
993
|
+
stream,
|
|
994
|
+
} from "convex-helpers/server/stream";
|
|
995
|
+
import type { Doc } from "./_generated/dataModel";
|
|
996
|
+
import schema from "./schema";
|
|
997
|
+
|
|
998
|
+
type Row = { account: Doc<"accounts">; project: Doc<"projects"> | null };
|
|
999
|
+
const fields = ["accountId", "_creationTime", "_id"];
|
|
1000
|
+
|
|
1001
|
+
const rows = stream(ctx.db, schema)
|
|
1002
|
+
.query("accounts")
|
|
1003
|
+
.withIndex("by_userId", (q) => q.eq("userId", userId))
|
|
1004
|
+
.flatMap(async (account) => {
|
|
1005
|
+
const projects = stream(ctx.db, schema)
|
|
1006
|
+
.query("projects")
|
|
1007
|
+
.withIndex("by_accountId", (q) => q.eq("accountId", account._id))
|
|
1008
|
+
.map<Row>(async (project) => ({ account, project }));
|
|
1009
|
+
|
|
1010
|
+
const marker = new SingletonStream<Row>(
|
|
1011
|
+
{ account, project: null },
|
|
1012
|
+
"asc",
|
|
1013
|
+
fields,
|
|
1014
|
+
[account._id, Infinity, ""], // After all projects in this account.
|
|
1015
|
+
[account._id], // Fixed equality prefix.
|
|
1016
|
+
);
|
|
1017
|
+
return mergedStream([projects, marker], fields);
|
|
1018
|
+
}, fields);
|
|
1019
|
+
|
|
1020
|
+
return await rows.paginate(paginationOpts);
|
|
1021
|
+
```
|
|
1022
|
+
|
|
1023
|
+
`Infinity` sorts after finite creation timestamps; use `-Infinity` to prepend.
|
|
1024
|
+
For descending streams, swap the signs and use `"desc"` throughout. This key
|
|
1025
|
+
choice is specific to the index above. `.map()` preserves index keys regardless
|
|
1026
|
+
of the returned row's shape. Use an object for the marker: a bare `null` is
|
|
1027
|
+
filtered out. Markers count toward the page size.
|
|
1028
|
+
|
|
977
1029
|
## Query Caching
|
|
978
1030
|
|
|
979
1031
|
Utilize a query cache implementation which persists subscriptions to the
|
|
@@ -1290,6 +1342,8 @@ http.route({
|
|
|
1290
1342
|
export default http;
|
|
1291
1343
|
```
|
|
1292
1344
|
|
|
1345
|
+
If you turn on `allowCredentials`, list the origins your frontend runs on in `allowedOrigins`. With `"*"`, any website can make requests that carry the user's cookies and read the responses. Note: if you authenticate with a bearer token in the `Authorization` header, you do not need `allowCredentials`.
|
|
1346
|
+
|
|
1293
1347
|
## Standard Schema
|
|
1294
1348
|
|
|
1295
1349
|
[Standard Schema](https://github.com/standard-schema/standard-schema)
|