You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- expand README with auth/admin helper usage examples
- document `createPrimitives` and Zod helpers behavior
- add AGENTS.md and CLAUDE.md notes to run `pnpm run ci`
Copy file name to clipboardExpand all lines: README.md
+73-4Lines changed: 73 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,10 +42,29 @@ export const {
42
42
});
43
43
```
44
44
45
+
`createPrimitives` returns six helpers:
46
+
47
+
-`authQuery`: Query that requires an authenticated user.
48
+
-`authMutation`: Mutation that requires an authenticated user.
49
+
-`authAction`: Action that requires an authenticated user.
50
+
-`adminQuery`: Query that requires an authenticated admin user.
51
+
-`adminMutation`: Mutation that requires an authenticated admin user.
52
+
-`adminAction`: Action that requires an authenticated admin user.
53
+
54
+
All six helpers resolve your user through `resolveUser`. They add `ctx.user` and `ctx.userId` to the handler context, and the `admin*` variants also enforce `isAdmin(user)`.
import { addSystemFields, zid } from'@amadeni/convex-lib';
68
117
import { z } from'zod';
69
118
70
119
const userId =zid('users');
71
120
72
-
const userShape =addSystemFields('users', {
73
-
email: z.string().email(),
74
-
role: z.string(),
121
+
const userSchema =z.object(
122
+
addSystemFields('users', {
123
+
email: z.string().email(),
124
+
role: z.string(),
125
+
}),
126
+
);
127
+
```
128
+
129
+
`zid('users')` gives you a Zod validator for a Convex document ID represented as a string. The table name is mainly for readability and type intent.
130
+
131
+
`addSystemFields('users', shape)` is useful when you already have a base document shape and want to extend it with the Convex-managed fields every stored document has:
132
+
133
+
-`_id`: The document ID for that table.
134
+
-`_creationTime`: The timestamp assigned by Convex.
135
+
136
+
It returns a Zod object shape, not a finished schema, so wrap it with `z.object(...)` as shown above.
0 commit comments