@robelest/convex-auth 0.0.4-preview.32 → 0.0.4-preview.33

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.
@@ -0,0 +1,59 @@
1
+ import { vGroupDoc, vGroupInviteDoc, vGroupMemberDoc, vPaginated, vUserDoc } from "../component/model.js";
2
+ import { v } from "convex/values";
3
+
4
+ //#region src/server/validators.ts
5
+ /**
6
+ * Public Convex `returns:` validators for the auth read surface.
7
+ *
8
+ * These back the `auth.v` namespace on the {@link createAuth} result.
9
+ * Consumers set them as their function `returns:` so client-side
10
+ * `useQuery` inference flows end-to-end with zero hand-rolled validators
11
+ * or DTO mappers. The `extend` field on User/Group/GroupMember is
12
+ * replaced with the validator the consumer supplied via
13
+ * `createAuth({ extend: { ... } })`, so `viewer.extend.<field>` is fully
14
+ * typed instead of `any`.
15
+ *
16
+ * @module
17
+ */
18
+ const docWithExtend = (fields, extend) => v.object({
19
+ ...fields,
20
+ extend: v.optional(extend)
21
+ });
22
+ /**
23
+ * Build the `auth.v.*` validator namespace from the consumer's `extend`
24
+ * config.
25
+ *
26
+ * `vUserDoc`/`vGroupDoc`/`vGroupMemberDoc` already declare an
27
+ * `extend: v.optional(v.any())` field; this rebuilds each with the
28
+ * supplied validator so the inferred type carries the real shape while
29
+ * the runtime validator still accepts the stored document.
30
+ *
31
+ * @typeParam TExtend - The consumer's per-table `extend` validators.
32
+ * @param extend - The `extend` map from `createAuth` config. Defaults to
33
+ * an empty object (all `extend` fields stay `v.any()`).
34
+ * @returns The `auth.v` namespace: `user`, `group`, `member`, `invite`,
35
+ * `viewer`, `viewerWithGroups`, and the `list` page-wrapper helper.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const av = buildAuthValidators({
40
+ * User: v.object({ lastActiveGroup: v.optional(v.string()) }),
41
+ * });
42
+ * // Infer<typeof av.viewer> -> User document with typed `extend`
43
+ * ```
44
+ */
45
+ function buildAuthValidators(extend = {}) {
46
+ const user = docWithExtend(vUserDoc.fields, extend.User ?? v.any());
47
+ return {
48
+ user,
49
+ group: docWithExtend(vGroupDoc.fields, extend.Group ?? v.any()),
50
+ member: docWithExtend(vGroupMemberDoc.fields, extend.GroupMember ?? v.any()),
51
+ invite: vGroupInviteDoc,
52
+ viewer: v.union(user, v.null()),
53
+ list: vPaginated
54
+ };
55
+ }
56
+
57
+ //#endregion
58
+ export { buildAuthValidators };
59
+ //# sourceMappingURL=validators.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robelest/convex-auth",
3
- "version": "0.0.4-preview.32",
3
+ "version": "0.0.4-preview.33",
4
4
  "description": "Authentication for Convex",
5
5
  "keywords": [
6
6
  "auth",