@vllnt/convex-memberships 0.1.0-canary.3fc56e6

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.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +144 -0
  3. package/dist/client/index.d.ts +114 -0
  4. package/dist/client/index.d.ts.map +1 -0
  5. package/dist/client/index.js +108 -0
  6. package/dist/client/index.js.map +1 -0
  7. package/dist/client/types.d.ts +56 -0
  8. package/dist/client/types.d.ts.map +1 -0
  9. package/dist/client/types.js +3 -0
  10. package/dist/client/types.js.map +1 -0
  11. package/dist/component/_generated/api.d.ts +38 -0
  12. package/dist/component/_generated/api.d.ts.map +1 -0
  13. package/dist/component/_generated/api.js +31 -0
  14. package/dist/component/_generated/api.js.map +1 -0
  15. package/dist/component/_generated/component.d.ts +116 -0
  16. package/dist/component/_generated/component.d.ts.map +1 -0
  17. package/dist/component/_generated/component.js +11 -0
  18. package/dist/component/_generated/component.js.map +1 -0
  19. package/dist/component/_generated/dataModel.d.ts +46 -0
  20. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  21. package/dist/component/_generated/dataModel.js +11 -0
  22. package/dist/component/_generated/dataModel.js.map +1 -0
  23. package/dist/component/_generated/server.d.ts +121 -0
  24. package/dist/component/_generated/server.d.ts.map +1 -0
  25. package/dist/component/_generated/server.js +78 -0
  26. package/dist/component/_generated/server.js.map +1 -0
  27. package/dist/component/convex.config.d.ts +3 -0
  28. package/dist/component/convex.config.d.ts.map +1 -0
  29. package/dist/component/convex.config.js +7 -0
  30. package/dist/component/convex.config.js.map +1 -0
  31. package/dist/component/mutations.d.ts +24 -0
  32. package/dist/component/mutations.d.ts.map +1 -0
  33. package/dist/component/mutations.js +96 -0
  34. package/dist/component/mutations.js.map +1 -0
  35. package/dist/component/queries.d.ts +80 -0
  36. package/dist/component/queries.d.ts.map +1 -0
  37. package/dist/component/queries.js +126 -0
  38. package/dist/component/queries.js.map +1 -0
  39. package/dist/component/schema.d.ts +33 -0
  40. package/dist/component/schema.d.ts.map +1 -0
  41. package/dist/component/schema.js +26 -0
  42. package/dist/component/schema.js.map +1 -0
  43. package/dist/component/validators.d.ts +146 -0
  44. package/dist/component/validators.d.ts.map +1 -0
  45. package/dist/component/validators.js +60 -0
  46. package/dist/component/validators.js.map +1 -0
  47. package/dist/react/index.d.ts +113 -0
  48. package/dist/react/index.d.ts.map +1 -0
  49. package/dist/react/index.js +80 -0
  50. package/dist/react/index.js.map +1 -0
  51. package/dist/shared.d.ts +20 -0
  52. package/dist/shared.d.ts.map +1 -0
  53. package/dist/shared.js +10 -0
  54. package/dist/shared.js.map +1 -0
  55. package/package.json +113 -0
  56. package/src/client/index.ts +270 -0
  57. package/src/client/types.ts +69 -0
  58. package/src/component/_generated/api.ts +54 -0
  59. package/src/component/_generated/component.ts +145 -0
  60. package/src/component/_generated/dataModel.ts +60 -0
  61. package/src/component/_generated/server.ts +156 -0
  62. package/src/component/convex.config.ts +9 -0
  63. package/src/component/mutations.ts +109 -0
  64. package/src/component/queries.ts +145 -0
  65. package/src/component/schema.ts +26 -0
  66. package/src/component/validators.ts +72 -0
  67. package/src/react/index.test.tsx +140 -0
  68. package/src/react/index.tsx +134 -0
  69. package/src/shared.ts +25 -0
  70. package/src/test.ts +12 -0
@@ -0,0 +1,126 @@
1
+ import { paginationOptsValidator } from "convex/server";
2
+ import { v } from "convex/values";
3
+ import { query } from "./_generated/server";
4
+ import { memberEntryPage, membershipDocPage, resourceEntryPage, } from "./validators";
5
+ export const listMembers = query({
6
+ args: {
7
+ resourceRef: v.string(),
8
+ relation: v.optional(v.string()),
9
+ paginationOpts: paginationOptsValidator,
10
+ },
11
+ returns: memberEntryPage,
12
+ handler: async (ctx, args) => {
13
+ const relation = args.relation;
14
+ const result = relation === undefined
15
+ ? await ctx.db
16
+ .query("memberships")
17
+ .withIndex("by_resource", (q) => q.eq("resourceRef", args.resourceRef))
18
+ .paginate(args.paginationOpts)
19
+ : await ctx.db
20
+ .query("memberships")
21
+ .withIndex("by_resource_relation", (q) => q.eq("resourceRef", args.resourceRef).eq("relation", relation))
22
+ .paginate(args.paginationOpts);
23
+ return {
24
+ page: result.page.map((row) => ({
25
+ memberRef: row.memberRef,
26
+ memberKind: row.memberKind,
27
+ relation: row.relation,
28
+ })),
29
+ isDone: result.isDone,
30
+ continueCursor: result.continueCursor,
31
+ };
32
+ },
33
+ });
34
+ export const members = query({
35
+ args: { memberRef: v.string(), paginationOpts: paginationOptsValidator },
36
+ returns: resourceEntryPage,
37
+ handler: async (ctx, args) => {
38
+ const result = await ctx.db
39
+ .query("memberships")
40
+ .withIndex("by_member", (q) => q.eq("memberRef", args.memberRef))
41
+ .paginate(args.paginationOpts);
42
+ return {
43
+ page: result.page.map((row) => ({
44
+ resourceRef: row.resourceRef,
45
+ relation: row.relation,
46
+ })),
47
+ isDone: result.isDone,
48
+ continueCursor: result.continueCursor,
49
+ };
50
+ },
51
+ });
52
+ /**
53
+ * Whether `memberRef` relates to `resourceRef` under the given `relation`, or
54
+ * under **any** stored relation when `relation` is omitted.
55
+ *
56
+ * @remarks
57
+ * **Security warning — unscoped path.** When `relation` is omitted this
58
+ * function returns `true` for **any** relation stored between the pair
59
+ * (e.g. `"invited"`, `"suspended"`, `"banned"`). Do **not** use the
60
+ * unscoped path as an authorization gate without first enumerating every
61
+ * relation your policy considers sufficient for the guarded action. Use the
62
+ * scoped path (`relation` provided) for authz checks, or enumerate
63
+ * acceptable relations explicitly before calling.
64
+ */
65
+ export const isMember = query({
66
+ args: {
67
+ memberRef: v.string(),
68
+ resourceRef: v.string(),
69
+ relation: v.optional(v.string()),
70
+ },
71
+ returns: v.boolean(),
72
+ handler: async (ctx, args) => {
73
+ const relation = args.relation;
74
+ if (relation !== undefined) {
75
+ const row = await ctx.db
76
+ .query("memberships")
77
+ .withIndex("by_tuple", (q) => q
78
+ .eq("memberRef", args.memberRef)
79
+ .eq("resourceRef", args.resourceRef)
80
+ .eq("relation", relation))
81
+ .first();
82
+ return row !== null;
83
+ }
84
+ const row = await ctx.db
85
+ .query("memberships")
86
+ .withIndex("by_member_resource", (q) => q.eq("memberRef", args.memberRef).eq("resourceRef", args.resourceRef))
87
+ .first();
88
+ return row !== null;
89
+ },
90
+ });
91
+ export const documents = query({
92
+ args: {
93
+ resourceRef: v.optional(v.string()),
94
+ memberRef: v.optional(v.string()),
95
+ paginationOpts: paginationOptsValidator,
96
+ },
97
+ returns: membershipDocPage,
98
+ handler: async (ctx, args) => {
99
+ const resourceRef = args.resourceRef;
100
+ const memberRef = args.memberRef;
101
+ const result = resourceRef !== undefined
102
+ ? await ctx.db
103
+ .query("memberships")
104
+ .withIndex("by_resource", (q) => q.eq("resourceRef", resourceRef))
105
+ .paginate(args.paginationOpts)
106
+ : memberRef !== undefined
107
+ ? await ctx.db
108
+ .query("memberships")
109
+ .withIndex("by_member", (q) => q.eq("memberRef", memberRef))
110
+ .paginate(args.paginationOpts)
111
+ : await ctx.db.query("memberships").paginate(args.paginationOpts);
112
+ return {
113
+ page: result.page.map((row) => ({
114
+ memberRef: row.memberRef,
115
+ memberKind: row.memberKind,
116
+ resourceRef: row.resourceRef,
117
+ relation: row.relation,
118
+ status: row.status,
119
+ createdAt: row.createdAt,
120
+ })),
121
+ isDone: result.isDone,
122
+ continueCursor: result.continueCursor,
123
+ };
124
+ },
125
+ });
126
+ //# sourceMappingURL=queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAEL,eAAe,EACf,iBAAiB,EAEjB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC;IAC/B,IAAI,EA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AG,CAAC,EAAE;iBACT,KAAK,CAAC,aAAa,CAAC;iBACpB,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;iBACjE,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC;YAClC,CAAC,CAAC,SAAS,KAAK,SAAS;gBACvB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;qBACT,KAAK,CAAC,aAAa,CAAC;qBACpB,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;qBAC3D,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC;gBAClC,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACxE,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;gBAC9B,SAAS,EAAE,GAAG,CAAC,SAAS;gBACxB,UAAU,EAAE,GAAG,CAAC,UAAU;gBAC1B,WAAW,EAAE,GAAG,CAAC,WAAW;gBAC5B,QAAQ,EAAE,GAAG,CAAC,QAAQ;gBACtB,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,SAAS,EAAE,GAAG,CAAC,SAAS;aACzB,CAAC,CAAC;YACH,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,cAAc,EAAE,MAAM,CAAC,cAAc;SACtC,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Sandboxed table — the relationship graph's own concern. A row is one flat
3
+ * ReBAC edge `(memberRef, resourceRef, relation)`. `memberRef`, `resourceRef`,
4
+ * `relation`, and `memberKind` are opaque host strings (never assume their
5
+ * shape). `status` is an opaque, optional lifecycle marker the host may stamp
6
+ * (e.g. `"active"`, `"invited"`); the component never inspects it. FLAT edges
7
+ * only — no transitive expansion in this version.
8
+ */
9
+ declare const _default: import("convex/server").SchemaDefinition<{
10
+ memberships: import("convex/server").TableDefinition<import("convex/values").VObject<{
11
+ status?: string | undefined;
12
+ memberRef: string;
13
+ memberKind: string;
14
+ resourceRef: string;
15
+ relation: string;
16
+ createdAt: number;
17
+ }, {
18
+ memberRef: import("convex/values").VString<string, "required">;
19
+ memberKind: import("convex/values").VString<string, "required">;
20
+ resourceRef: import("convex/values").VString<string, "required">;
21
+ relation: import("convex/values").VString<string, "required">;
22
+ status: import("convex/values").VString<string | undefined, "optional">;
23
+ createdAt: import("convex/values").VFloat64<number, "required">;
24
+ }, "required", "memberRef" | "memberKind" | "resourceRef" | "relation" | "status" | "createdAt">, {
25
+ by_member: ["memberRef", "_creationTime"];
26
+ by_resource: ["resourceRef", "_creationTime"];
27
+ by_resource_relation: ["resourceRef", "relation", "_creationTime"];
28
+ by_member_resource: ["memberRef", "resourceRef", "_creationTime"];
29
+ by_tuple: ["memberRef", "resourceRef", "relation", "_creationTime"];
30
+ }, {}, {}>;
31
+ }, true>;
32
+ export default _default;
33
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;;;;;;;;;;;;;;;;;;;;;;;;AACH,wBAcG"}
@@ -0,0 +1,26 @@
1
+ import { defineSchema, defineTable } from "convex/server";
2
+ import { v } from "convex/values";
3
+ /**
4
+ * Sandboxed table — the relationship graph's own concern. A row is one flat
5
+ * ReBAC edge `(memberRef, resourceRef, relation)`. `memberRef`, `resourceRef`,
6
+ * `relation`, and `memberKind` are opaque host strings (never assume their
7
+ * shape). `status` is an opaque, optional lifecycle marker the host may stamp
8
+ * (e.g. `"active"`, `"invited"`); the component never inspects it. FLAT edges
9
+ * only — no transitive expansion in this version.
10
+ */
11
+ export default defineSchema({
12
+ memberships: defineTable({
13
+ memberRef: v.string(),
14
+ memberKind: v.string(),
15
+ resourceRef: v.string(),
16
+ relation: v.string(),
17
+ status: v.optional(v.string()),
18
+ createdAt: v.number(),
19
+ })
20
+ .index("by_member", ["memberRef"])
21
+ .index("by_resource", ["resourceRef"])
22
+ .index("by_resource_relation", ["resourceRef", "relation"])
23
+ .index("by_member_resource", ["memberRef", "resourceRef"])
24
+ .index("by_tuple", ["memberRef", "resourceRef", "relation"]),
25
+ });
26
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC;;;;;;;GAOG;AACH,eAAe,YAAY,CAAC;IAC1B,WAAW,EAAE,WAAW,CAAC;QACvB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;QACrB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;QACtB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;QACvB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;QACpB,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAC9B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;KACtB,CAAC;SACC,KAAK,CAAC,WAAW,EAAE,CAAC,WAAW,CAAC,CAAC;SACjC,KAAK,CAAC,aAAa,EAAE,CAAC,aAAa,CAAC,CAAC;SACrC,KAAK,CAAC,sBAAsB,EAAE,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;SAC1D,KAAK,CAAC,oBAAoB,EAAE,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;SACzD,KAAK,CAAC,UAAU,EAAE,CAAC,WAAW,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;CAC/D,CAAC,CAAC"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * What a tuple's `memberRef` points at — an opaque, host-classified string
3
+ * (e.g. `"user"`, `"group"`, `"resource"`, or any host-defined kind). The
4
+ * component never interprets it. Defaults to `"user"` when the host omits it.
5
+ */
6
+ export declare const memberKind: import("convex/values").VString<string, "required">;
7
+ /** A full membership edge as stored — returned by document-shaped queries. */
8
+ export declare const membershipDoc: import("convex/values").VObject<{
9
+ status?: string | undefined;
10
+ memberRef: string;
11
+ memberKind: string;
12
+ resourceRef: string;
13
+ relation: string;
14
+ createdAt: number;
15
+ }, {
16
+ memberRef: import("convex/values").VString<string, "required">;
17
+ memberKind: import("convex/values").VString<string, "required">;
18
+ resourceRef: import("convex/values").VString<string, "required">;
19
+ relation: import("convex/values").VString<string, "required">;
20
+ status: import("convex/values").VString<string | undefined, "optional">;
21
+ createdAt: import("convex/values").VFloat64<number, "required">;
22
+ }, "required", "memberRef" | "memberKind" | "resourceRef" | "relation" | "status" | "createdAt">;
23
+ /** Projection returned by `listMembers` — who relates to a resource, and how. */
24
+ export declare const memberEntry: import("convex/values").VObject<{
25
+ memberRef: string;
26
+ memberKind: string;
27
+ relation: string;
28
+ }, {
29
+ memberRef: import("convex/values").VString<string, "required">;
30
+ memberKind: import("convex/values").VString<string, "required">;
31
+ relation: import("convex/values").VString<string, "required">;
32
+ }, "required", "memberRef" | "memberKind" | "relation">;
33
+ /** Projection returned by `members` — which resources a member relates to, and how. */
34
+ export declare const resourceEntry: import("convex/values").VObject<{
35
+ resourceRef: string;
36
+ relation: string;
37
+ }, {
38
+ resourceRef: import("convex/values").VString<string, "required">;
39
+ relation: import("convex/values").VString<string, "required">;
40
+ }, "required", "resourceRef" | "relation">;
41
+ /** A stable code-tag explaining why a `setRelation` was rejected. */
42
+ export declare const setRelationReason: import("convex/values").VUnion<"NOT_FOUND" | "EXISTS", [import("convex/values").VLiteral<"NOT_FOUND", "required">, import("convex/values").VLiteral<"EXISTS", "required">], "required", never>;
43
+ /**
44
+ * Result of `setRelation`. `reason` carries a stable code-tag (`NOT_FOUND`,
45
+ * `EXISTS`) when `ok` is false.
46
+ */
47
+ export declare const setRelationResult: import("convex/values").VObject<{
48
+ reason?: "NOT_FOUND" | "EXISTS" | undefined;
49
+ ok: boolean;
50
+ }, {
51
+ ok: import("convex/values").VBoolean<boolean, "required">;
52
+ reason: import("convex/values").VUnion<"NOT_FOUND" | "EXISTS" | undefined, [import("convex/values").VLiteral<"NOT_FOUND", "required">, import("convex/values").VLiteral<"EXISTS", "required">], "optional", never>;
53
+ }, "required", "ok" | "reason">;
54
+ /** Result of `remove` — `removed` is true when an edge was actually deleted. */
55
+ export declare const removeResult: import("convex/values").VObject<{
56
+ removed: boolean;
57
+ }, {
58
+ removed: import("convex/values").VBoolean<boolean, "required">;
59
+ }, "required", "removed">;
60
+ /** A page of `MemberEntry` rows, as returned by a paginated `listMembers`. */
61
+ export declare const memberEntryPage: import("convex/values").VObject<{
62
+ page: {
63
+ memberRef: string;
64
+ memberKind: string;
65
+ relation: string;
66
+ }[];
67
+ isDone: boolean;
68
+ continueCursor: string;
69
+ }, {
70
+ page: import("convex/values").VArray<{
71
+ memberRef: string;
72
+ memberKind: string;
73
+ relation: string;
74
+ }[], import("convex/values").VObject<{
75
+ memberRef: string;
76
+ memberKind: string;
77
+ relation: string;
78
+ }, {
79
+ memberRef: import("convex/values").VString<string, "required">;
80
+ memberKind: import("convex/values").VString<string, "required">;
81
+ relation: import("convex/values").VString<string, "required">;
82
+ }, "required", "memberRef" | "memberKind" | "relation">, "required">;
83
+ isDone: import("convex/values").VBoolean<boolean, "required">;
84
+ continueCursor: import("convex/values").VString<string, "required">;
85
+ }, "required", "page" | "isDone" | "continueCursor">;
86
+ /** A page of `ResourceEntry` rows, as returned by a paginated `members`. */
87
+ export declare const resourceEntryPage: import("convex/values").VObject<{
88
+ page: {
89
+ resourceRef: string;
90
+ relation: string;
91
+ }[];
92
+ isDone: boolean;
93
+ continueCursor: string;
94
+ }, {
95
+ page: import("convex/values").VArray<{
96
+ resourceRef: string;
97
+ relation: string;
98
+ }[], import("convex/values").VObject<{
99
+ resourceRef: string;
100
+ relation: string;
101
+ }, {
102
+ resourceRef: import("convex/values").VString<string, "required">;
103
+ relation: import("convex/values").VString<string, "required">;
104
+ }, "required", "resourceRef" | "relation">, "required">;
105
+ isDone: import("convex/values").VBoolean<boolean, "required">;
106
+ continueCursor: import("convex/values").VString<string, "required">;
107
+ }, "required", "page" | "isDone" | "continueCursor">;
108
+ /** A page of full membership docs, as returned by the paginated `documents`. */
109
+ export declare const membershipDocPage: import("convex/values").VObject<{
110
+ page: {
111
+ status?: string | undefined;
112
+ memberRef: string;
113
+ memberKind: string;
114
+ resourceRef: string;
115
+ relation: string;
116
+ createdAt: number;
117
+ }[];
118
+ isDone: boolean;
119
+ continueCursor: string;
120
+ }, {
121
+ page: import("convex/values").VArray<{
122
+ status?: string | undefined;
123
+ memberRef: string;
124
+ memberKind: string;
125
+ resourceRef: string;
126
+ relation: string;
127
+ createdAt: number;
128
+ }[], import("convex/values").VObject<{
129
+ status?: string | undefined;
130
+ memberRef: string;
131
+ memberKind: string;
132
+ resourceRef: string;
133
+ relation: string;
134
+ createdAt: number;
135
+ }, {
136
+ memberRef: import("convex/values").VString<string, "required">;
137
+ memberKind: import("convex/values").VString<string, "required">;
138
+ resourceRef: import("convex/values").VString<string, "required">;
139
+ relation: import("convex/values").VString<string, "required">;
140
+ status: import("convex/values").VString<string | undefined, "optional">;
141
+ createdAt: import("convex/values").VFloat64<number, "required">;
142
+ }, "required", "memberRef" | "memberKind" | "resourceRef" | "relation" | "status" | "createdAt">, "required">;
143
+ isDone: import("convex/values").VBoolean<boolean, "required">;
144
+ continueCursor: import("convex/values").VString<string, "required">;
145
+ }, "required", "page" | "isDone" | "continueCursor">;
146
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,UAAU,qDAAa,CAAC;AAErC,8EAA8E;AAC9E,eAAO,MAAM,aAAa;;;;;;;;;;;;;;gGAOxB,CAAC;AAEH,iFAAiF;AACjF,eAAO,MAAM,WAAW;;;;;;;;uDAItB,CAAC;AAEH,uFAAuF;AACvF,eAAO,MAAM,aAAa;;;;;;0CAGxB,CAAC;AAEH,qEAAqE;AACrE,eAAO,MAAM,iBAAiB,gMAG7B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;;;+BAG5B,CAAC;AAEH,gFAAgF;AAChF,eAAO,MAAM,YAAY;;;;yBAEvB,CAAC;AAEH,8EAA8E;AAC9E,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;oDAI1B,CAAC;AAEH,4EAA4E;AAC5E,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;oDAI5B,CAAC;AAEH,gFAAgF;AAChF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oDAI5B,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { v } from "convex/values";
2
+ /**
3
+ * What a tuple's `memberRef` points at — an opaque, host-classified string
4
+ * (e.g. `"user"`, `"group"`, `"resource"`, or any host-defined kind). The
5
+ * component never interprets it. Defaults to `"user"` when the host omits it.
6
+ */
7
+ export const memberKind = v.string();
8
+ /** A full membership edge as stored — returned by document-shaped queries. */
9
+ export const membershipDoc = v.object({
10
+ memberRef: v.string(),
11
+ memberKind,
12
+ resourceRef: v.string(),
13
+ relation: v.string(),
14
+ status: v.optional(v.string()),
15
+ createdAt: v.number(),
16
+ });
17
+ /** Projection returned by `listMembers` — who relates to a resource, and how. */
18
+ export const memberEntry = v.object({
19
+ memberRef: v.string(),
20
+ memberKind,
21
+ relation: v.string(),
22
+ });
23
+ /** Projection returned by `members` — which resources a member relates to, and how. */
24
+ export const resourceEntry = v.object({
25
+ resourceRef: v.string(),
26
+ relation: v.string(),
27
+ });
28
+ /** A stable code-tag explaining why a `setRelation` was rejected. */
29
+ export const setRelationReason = v.union(v.literal("NOT_FOUND"), v.literal("EXISTS"));
30
+ /**
31
+ * Result of `setRelation`. `reason` carries a stable code-tag (`NOT_FOUND`,
32
+ * `EXISTS`) when `ok` is false.
33
+ */
34
+ export const setRelationResult = v.object({
35
+ ok: v.boolean(),
36
+ reason: v.optional(setRelationReason),
37
+ });
38
+ /** Result of `remove` — `removed` is true when an edge was actually deleted. */
39
+ export const removeResult = v.object({
40
+ removed: v.boolean(),
41
+ });
42
+ /** A page of `MemberEntry` rows, as returned by a paginated `listMembers`. */
43
+ export const memberEntryPage = v.object({
44
+ page: v.array(memberEntry),
45
+ isDone: v.boolean(),
46
+ continueCursor: v.string(),
47
+ });
48
+ /** A page of `ResourceEntry` rows, as returned by a paginated `members`. */
49
+ export const resourceEntryPage = v.object({
50
+ page: v.array(resourceEntry),
51
+ isDone: v.boolean(),
52
+ continueCursor: v.string(),
53
+ });
54
+ /** A page of full membership docs, as returned by the paginated `documents`. */
55
+ export const membershipDocPage = v.object({
56
+ page: v.array(membershipDoc),
57
+ isDone: v.boolean(),
58
+ continueCursor: v.string(),
59
+ });
60
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;AAErC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,UAAU;IACV,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,QAAQ,EAAE,CAAC,CAAC,MAAM,EA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AC;AAEH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC;IAC5B,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;IACnB,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;CAC3B,CAAC,CAAC;AAEH,gFAAgF;AAChF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC;IAC5B,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;IACnB,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;CAC3B,CAAC,CAAC"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Optional React front-end tooling for `@vllnt/convex-memberships`.
3
+ *
4
+ * Thin, tree-shakeable hooks over `convex/react`'s `useQuery`. Each hook takes
5
+ * the **host app's** re-exported component function reference (the host owns its
6
+ * `api`; this layer never imports it) plus the query args, and returns the
7
+ * query result or `undefined` while it loads.
8
+ *
9
+ * `react` and `convex` are optional peer dependencies — a backend-only consumer
10
+ * pulls none of this. Only metadata derived from the host's own refs reaches the
11
+ * client; the component holds no secrets to leak.
12
+ *
13
+ * @module
14
+ */
15
+ import { useQuery } from "convex/react";
16
+ import type { FunctionReference } from "convex/server";
17
+ import type { MemberEntry, Page, ResourceEntry } from "../client/types.js";
18
+ /**
19
+ * A reference to the component's `isMember` query, as re-exported by the host
20
+ * (e.g. `api.memberships.isMember`). Resolves whether a member relates to a
21
+ * resource, optionally under a specific relation.
22
+ */
23
+ export type IsMemberRef = FunctionReference<"query", "public", {
24
+ memberRef: string;
25
+ resourceRef: string;
26
+ relation?: string;
27
+ }, boolean>;
28
+ /**
29
+ * A reference to the component's `members` query, as re-exported by the host
30
+ * (e.g. `api.memberships.members`). Returns a page of resources a member
31
+ * relates to.
32
+ */
33
+ export type MembersRef = FunctionReference<"query", "public", {
34
+ memberRef: string;
35
+ paginationOpts: {
36
+ numItems: number;
37
+ cursor: string | null;
38
+ };
39
+ }, Page<ResourceEntry>>;
40
+ /**
41
+ * A reference to the component's `listMembers` query, as re-exported by the host
42
+ * (e.g. `api.memberships.listMembers`). Returns a page of members of a resource,
43
+ * optionally filtered to one relation.
44
+ */
45
+ export type ListMembersRef = FunctionReference<"query", "public", {
46
+ resourceRef: string;
47
+ relation?: string;
48
+ paginationOpts: {
49
+ numItems: number;
50
+ cursor: string | null;
51
+ };
52
+ }, Page<MemberEntry>>;
53
+ /**
54
+ * Reactively check whether `memberRef` relates to `resourceRef`.
55
+ *
56
+ * @param isMemberRef - the host's re-exported `isMember` query reference.
57
+ * @param args - `memberRef` and `resourceRef`; with `relation`, checks that
58
+ * exact edge, without it checks any relation between the two.
59
+ * @returns `true`/`false`, or `undefined` while the query loads.
60
+ *
61
+ * @example
62
+ * ```tsx
63
+ * const isMember = useIsMember(api.memberships.isMember, {
64
+ * memberRef: userId,
65
+ * resourceRef: orgId,
66
+ * relation: "admin",
67
+ * });
68
+ * ```
69
+ */
70
+ export declare function useIsMember(isMemberRef: IsMemberRef, args: {
71
+ memberRef: string;
72
+ resourceRef: string;
73
+ relation?: string;
74
+ }): boolean | undefined;
75
+ /**
76
+ * Reactively list the resources `memberRef` relates to (one page).
77
+ *
78
+ * @param membersRef - the host's re-exported `members` query reference.
79
+ * @param args - `memberRef` to resolve memberships for. Page size and cursor are
80
+ * managed by the host's re-exported query; this hook requests the first page.
81
+ * @returns the resource-entry page, or `undefined` while the query loads.
82
+ *
83
+ * @example
84
+ * ```tsx
85
+ * const page = useMembers(api.memberships.members, { memberRef: userId });
86
+ * ```
87
+ */
88
+ export declare function useMembers(membersRef: MembersRef, args: {
89
+ memberRef: string;
90
+ }): ReturnType<typeof useQuery<MembersRef>>;
91
+ /**
92
+ * Reactively list the members of `resourceRef` (one page), optionally filtered
93
+ * to a single `relation`.
94
+ *
95
+ * @param listMembersRef - the host's re-exported `listMembers` query reference.
96
+ * @param args - `resourceRef` to resolve members for, and an optional `relation`
97
+ * filter. Page size and cursor are managed by the host's re-exported query; this
98
+ * hook requests the first page.
99
+ * @returns the member-entry page, or `undefined` while the query loads.
100
+ *
101
+ * @example
102
+ * ```tsx
103
+ * const page = useListMembers(api.memberships.listMembers, {
104
+ * resourceRef: orgId,
105
+ * relation: "admin",
106
+ * });
107
+ * ```
108
+ */
109
+ export declare function useListMembers(listMembersRef: ListMembersRef, args: {
110
+ resourceRef: string;
111
+ relation?: string;
112
+ }): ReturnType<typeof useQuery<ListMembersRef>>;
113
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE3E;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,iBAAiB,CACzC,OAAO,EACP,QAAQ,EACR;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,EAC7D,OAAO,CACR,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,iBAAiB,CACxC,OAAO,EACP,QAAQ,EACR;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAA;CAAE,EAClF,IAAI,CAAC,aAAa,CAAC,CACpB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,iBAAiB,CAC5C,OAAO,EACP,QAAQ,EACR;IACE,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CAC7D,EACD,IAAI,CAAC,WAAW,CAAC,CAClB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CACzB,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAClE,OAAO,GAAG,SAAS,CAErB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CACxB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAC1B,UAAU,CAAC,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC,CAKzC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAC5B,cAAc,EAAE,cAAc,EAC9B,IAAI,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/C,UAAU,CAAC,OAAO,QAAQ,CAAC,cAAc,CAAC,CAAC,CAM7C"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Optional React front-end tooling for `@vllnt/convex-memberships`.
3
+ *
4
+ * Thin, tree-shakeable hooks over `convex/react`'s `useQuery`. Each hook takes
5
+ * the **host app's** re-exported component function reference (the host owns its
6
+ * `api`; this layer never imports it) plus the query args, and returns the
7
+ * query result or `undefined` while it loads.
8
+ *
9
+ * `react` and `convex` are optional peer dependencies — a backend-only consumer
10
+ * pulls none of this. Only metadata derived from the host's own refs reaches the
11
+ * client; the component holds no secrets to leak.
12
+ *
13
+ * @module
14
+ */
15
+ import { useQuery } from "convex/react";
16
+ /**
17
+ * Reactively check whether `memberRef` relates to `resourceRef`.
18
+ *
19
+ * @param isMemberRef - the host's re-exported `isMember` query reference.
20
+ * @param args - `memberRef` and `resourceRef`; with `relation`, checks that
21
+ * exact edge, without it checks any relation between the two.
22
+ * @returns `true`/`false`, or `undefined` while the query loads.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * const isMember = useIsMember(api.memberships.isMember, {
27
+ * memberRef: userId,
28
+ * resourceRef: orgId,
29
+ * relation: "admin",
30
+ * });
31
+ * ```
32
+ */
33
+ export function useIsMember(isMemberRef, args) {
34
+ return useQuery(isMemberRef, args);
35
+ }
36
+ /**
37
+ * Reactively list the resources `memberRef` relates to (one page).
38
+ *
39
+ * @param membersRef - the host's re-exported `members` query reference.
40
+ * @param args - `memberRef` to resolve memberships for. Page size and cursor are
41
+ * managed by the host's re-exported query; this hook requests the first page.
42
+ * @returns the resource-entry page, or `undefined` while the query loads.
43
+ *
44
+ * @example
45
+ * ```tsx
46
+ * const page = useMembers(api.memberships.members, { memberRef: userId });
47
+ * ```
48
+ */
49
+ export function useMembers(membersRef, args) {
50
+ return useQuery(membersRef, {
51
+ memberRef: args.memberRef,
52
+ paginationOpts: { numItems: 100, cursor: null },
53
+ });
54
+ }
55
+ /**
56
+ * Reactively list the members of `resourceRef` (one page), optionally filtered
57
+ * to a single `relation`.
58
+ *
59
+ * @param listMembersRef - the host's re-exported `listMembers` query reference.
60
+ * @param args - `resourceRef` to resolve members for, and an optional `relation`
61
+ * filter. Page size and cursor are managed by the host's re-exported query; this
62
+ * hook requests the first page.
63
+ * @returns the member-entry page, or `undefined` while the query loads.
64
+ *
65
+ * @example
66
+ * ```tsx
67
+ * const page = useListMembers(api.memberships.listMembers, {
68
+ * resourceRef: orgId,
69
+ * relation: "admin",
70
+ * });
71
+ * ```
72
+ */
73
+ export function useListMembers(listMembersRef, args) {
74
+ return useQuery(listMembersRef, {
75
+ resourceRef: args.resourceRef,
76
+ relation: args.relation,
77
+ paginationOpts: { numItems: 100, cursor: null },
78
+ });
79
+ }
80
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AA4CxC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,WAAW,CACzB,WAAwB,EACxB,IAAmE;IAEnE,OAAO,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CACxB,UAAsB,EACtB,IAA2B;IAE3B,OAAO,QAAQ,CAAC,UAAU,EAAE;QAC1B,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,cAAc,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;KAChD,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,cAAc,CAC5B,cAA8B,EAC9B,IAAgD;IAEhD,OAAO,QAAQ,CAAC,cAAc,EAAE;QAC9B,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,cAAc,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;KAChD,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,20 @@
1
+ /** Shared constants + types used by both `client/` and `component/`. */
2
+ export declare const COMPONENT_NAME = "memberships";
3
+ /**
4
+ * Default relation applied when the host does not name one. A flat ReBAC tuple
5
+ * is `(memberRef, resourceRef, relation)`; this is the relation fallback.
6
+ */
7
+ export declare const DEFAULT_RELATION = "member";
8
+ /** Default member kind applied when the host does not classify the member. */
9
+ export declare const DEFAULT_MEMBER_KIND = "user";
10
+ /**
11
+ * What a member tuple's `memberRef` points at. An opaque, host-classified
12
+ * string (e.g. `"user"`, `"group"`, `"resource"`, or any host-defined kind) —
13
+ * the component never interprets it.
14
+ */
15
+ export type MemberKind = string;
16
+ /** Opaque host-supplied member reference. Never assume its shape or source. */
17
+ export type MemberRef = string;
18
+ /** Opaque host-supplied resource reference. Never assume its shape or source. */
19
+ export type ResourceRef = string;
20
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,gBAAgB,WAAW,CAAC;AAEzC,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAE1C;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC,+EAA+E;AAC/E,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B,iFAAiF;AACjF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC"}