@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.
- package/LICENSE +21 -0
- package/README.md +144 -0
- package/dist/client/index.d.ts +114 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +108 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +56 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +3 -0
- package/dist/client/types.js.map +1 -0
- package/dist/component/_generated/api.d.ts +38 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +116 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +7 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/mutations.d.ts +24 -0
- package/dist/component/mutations.d.ts.map +1 -0
- package/dist/component/mutations.js +96 -0
- package/dist/component/mutations.js.map +1 -0
- package/dist/component/queries.d.ts +80 -0
- package/dist/component/queries.d.ts.map +1 -0
- package/dist/component/queries.js +126 -0
- package/dist/component/queries.js.map +1 -0
- package/dist/component/schema.d.ts +33 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +26 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/validators.d.ts +146 -0
- package/dist/component/validators.d.ts.map +1 -0
- package/dist/component/validators.js +60 -0
- package/dist/component/validators.js.map +1 -0
- package/dist/react/index.d.ts +113 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +80 -0
- package/dist/react/index.js.map +1 -0
- package/dist/shared.d.ts +20 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +10 -0
- package/dist/shared.js.map +1 -0
- package/package.json +113 -0
- package/src/client/index.ts +270 -0
- package/src/client/types.ts +69 -0
- package/src/component/_generated/api.ts +54 -0
- package/src/component/_generated/component.ts +145 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +156 -0
- package/src/component/convex.config.ts +9 -0
- package/src/component/mutations.ts +109 -0
- package/src/component/queries.ts +145 -0
- package/src/component/schema.ts +26 -0
- package/src/component/validators.ts +72 -0
- package/src/react/index.test.tsx +140 -0
- package/src/react/index.tsx +134 -0
- package/src/shared.ts +25 -0
- package/src/test.ts +12 -0
package/dist/shared.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Shared constants + types used by both `client/` and `component/`. */
|
|
2
|
+
export 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 const DEFAULT_RELATION = "member";
|
|
8
|
+
/** Default member kind applied when the host does not classify the member. */
|
|
9
|
+
export const DEFAULT_MEMBER_KIND = "user";
|
|
10
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAC;AAE5C;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAEzC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vllnt/convex-memberships",
|
|
3
|
+
"version": "0.1.0-canary.3fc56e6",
|
|
4
|
+
"description": "Auth-agnostic membership and relationship graph (ReBAC tuples), as a Convex component",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"packageManager": "pnpm@9.15.4",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"src"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
"./package.json": "./package.json",
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/client/index.d.ts",
|
|
16
|
+
"default": "./dist/client/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./react": {
|
|
19
|
+
"types": "./dist/react/index.d.ts",
|
|
20
|
+
"default": "./dist/react/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./test": "./src/test.ts",
|
|
23
|
+
"./_generated/component.js": {
|
|
24
|
+
"types": "./dist/component/_generated/component.d.ts"
|
|
25
|
+
},
|
|
26
|
+
"./_generated/component": {
|
|
27
|
+
"types": "./dist/component/_generated/component.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./convex.config": {
|
|
30
|
+
"types": "./dist/component/convex.config.d.ts",
|
|
31
|
+
"default": "./dist/component/convex.config.js"
|
|
32
|
+
},
|
|
33
|
+
"./convex.config.js": {
|
|
34
|
+
"types": "./dist/component/convex.config.d.ts",
|
|
35
|
+
"default": "./dist/component/convex.config.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"types": "./dist/client/index.d.ts",
|
|
39
|
+
"module": "./dist/client/index.js",
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc --project ./tsconfig.build.json",
|
|
42
|
+
"build:codegen": "pnpm convex codegen --component-dir ./src/component && pnpm build",
|
|
43
|
+
"build:clean": "rm -rf dist *.tsbuildinfo && pnpm build:codegen",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"typecheck:ci": "tsc --noEmit --project tsconfig.ci.json",
|
|
46
|
+
"lint": "eslint .",
|
|
47
|
+
"test": "vitest run --passWithNoTests",
|
|
48
|
+
"test:watch": "vitest --typecheck --clearScreen false",
|
|
49
|
+
"test:coverage": "vitest run --coverage --coverage.reporter=text",
|
|
50
|
+
"generate:llms": "node scripts/generate-llms.mjs",
|
|
51
|
+
"preversion": "pnpm install --frozen-lockfile && pnpm build && pnpm test:coverage && pnpm typecheck && pnpm generate:llms",
|
|
52
|
+
"prepublishOnly": "npm whoami || npm login",
|
|
53
|
+
"alpha": "npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
|
|
54
|
+
"release": "npm version patch && npm publish && git push --follow-tags"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"convex": "^1.41.0",
|
|
59
|
+
"react": ">=18"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@edge-runtime/vm": "^5.0.0",
|
|
63
|
+
"@testing-library/dom": "^10.4.1",
|
|
64
|
+
"@testing-library/react": "^16.3.2",
|
|
65
|
+
"@types/react": "^19.2.17",
|
|
66
|
+
"@types/react-dom": "^19.2.3",
|
|
67
|
+
"@vitest/coverage-v8": "^4.1.8",
|
|
68
|
+
"@vllnt/eslint-config": "^1.0.0",
|
|
69
|
+
"@vllnt/typescript": "^1.0.0",
|
|
70
|
+
"convex": "^1.41.0",
|
|
71
|
+
"convex-test": "^0.0.53",
|
|
72
|
+
"eslint": "^9.0.0",
|
|
73
|
+
"jsdom": "^29.1.1",
|
|
74
|
+
"prettier": "^3.4.0",
|
|
75
|
+
"react": "^19.2.7",
|
|
76
|
+
"react-dom": "^19.2.7",
|
|
77
|
+
"typescript": "^5.7.0",
|
|
78
|
+
"vitest": "^4.1.8"
|
|
79
|
+
},
|
|
80
|
+
"homepage": "https://github.com/vllnt/convex-memberships#readme",
|
|
81
|
+
"bugs": {
|
|
82
|
+
"url": "https://github.com/vllnt/convex-memberships/issues"
|
|
83
|
+
},
|
|
84
|
+
"author": {
|
|
85
|
+
"name": "bntvllnt",
|
|
86
|
+
"url": "https://bntvllnt.com"
|
|
87
|
+
},
|
|
88
|
+
"funding": {
|
|
89
|
+
"type": "github",
|
|
90
|
+
"url": "https://github.com/sponsors/bntvllnt"
|
|
91
|
+
},
|
|
92
|
+
"repository": {
|
|
93
|
+
"type": "git",
|
|
94
|
+
"url": "https://github.com/vllnt/convex-memberships"
|
|
95
|
+
},
|
|
96
|
+
"engines": {
|
|
97
|
+
"node": ">=18"
|
|
98
|
+
},
|
|
99
|
+
"publishConfig": {
|
|
100
|
+
"access": "public"
|
|
101
|
+
},
|
|
102
|
+
"sideEffects": false,
|
|
103
|
+
"keywords": [
|
|
104
|
+
"convex",
|
|
105
|
+
"convex-component",
|
|
106
|
+
"memberships"
|
|
107
|
+
],
|
|
108
|
+
"peerDependenciesMeta": {
|
|
109
|
+
"react": {
|
|
110
|
+
"optional": true
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FunctionArgs,
|
|
3
|
+
FunctionReference,
|
|
4
|
+
FunctionReturnType,
|
|
5
|
+
PaginationOptions,
|
|
6
|
+
} from "convex/server";
|
|
7
|
+
import type {
|
|
8
|
+
MemberEntry,
|
|
9
|
+
MemberKind,
|
|
10
|
+
MembershipDoc,
|
|
11
|
+
MembershipsOptions,
|
|
12
|
+
Page,
|
|
13
|
+
RemoveResult,
|
|
14
|
+
ResourceEntry,
|
|
15
|
+
SetRelationResult,
|
|
16
|
+
} from "./types.js";
|
|
17
|
+
import { DEFAULT_MEMBER_KIND, DEFAULT_RELATION } from "../shared.js";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The memberships component's function references, as exposed on the host via
|
|
21
|
+
* `components.memberships`.
|
|
22
|
+
*/
|
|
23
|
+
export interface MembershipsComponent {
|
|
24
|
+
mutations: {
|
|
25
|
+
add: FunctionReference<
|
|
26
|
+
"mutation",
|
|
27
|
+
"internal",
|
|
28
|
+
{
|
|
29
|
+
memberRef: string;
|
|
30
|
+
memberKind: MemberKind;
|
|
31
|
+
resourceRef: string;
|
|
32
|
+
relation: string;
|
|
33
|
+
status?: string;
|
|
34
|
+
},
|
|
35
|
+
string
|
|
36
|
+
>;
|
|
37
|
+
remove: FunctionReference<
|
|
38
|
+
"mutation",
|
|
39
|
+
"internal",
|
|
40
|
+
{ memberRef: string; resourceRef: string; relation: string },
|
|
41
|
+
RemoveResult
|
|
42
|
+
>;
|
|
43
|
+
setRelation: FunctionReference<
|
|
44
|
+
"mutation",
|
|
45
|
+
"internal",
|
|
46
|
+
{
|
|
47
|
+
memberRef: string;
|
|
48
|
+
resourceRef: string;
|
|
49
|
+
fromRelation: string;
|
|
50
|
+
toRelation: string;
|
|
51
|
+
},
|
|
52
|
+
SetRelationResult
|
|
53
|
+
>;
|
|
54
|
+
};
|
|
55
|
+
queries: {
|
|
56
|
+
listMembers: FunctionReference<
|
|
57
|
+
"query",
|
|
58
|
+
"internal",
|
|
59
|
+
{
|
|
60
|
+
resourceRef: string;
|
|
61
|
+
relation?: string;
|
|
62
|
+
paginationOpts: PaginationOptions;
|
|
63
|
+
},
|
|
64
|
+
Page<MemberEntry>
|
|
65
|
+
>;
|
|
66
|
+
members: FunctionReference<
|
|
67
|
+
"query",
|
|
68
|
+
"internal",
|
|
69
|
+
{ memberRef: string; paginationOpts: PaginationOptions },
|
|
70
|
+
Page<ResourceEntry>
|
|
71
|
+
>;
|
|
72
|
+
isMember: FunctionReference<
|
|
73
|
+
"query",
|
|
74
|
+
"internal",
|
|
75
|
+
{ memberRef: string; resourceRef: string; relation?: string },
|
|
76
|
+
boolean
|
|
77
|
+
>;
|
|
78
|
+
documents: FunctionReference<
|
|
79
|
+
"query",
|
|
80
|
+
"internal",
|
|
81
|
+
{
|
|
82
|
+
resourceRef?: string;
|
|
83
|
+
memberRef?: string;
|
|
84
|
+
paginationOpts: PaginationOptions;
|
|
85
|
+
},
|
|
86
|
+
Page<MembershipDoc>
|
|
87
|
+
>;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface RunQueryCtx {
|
|
92
|
+
runQuery<Q extends FunctionReference<"query", "internal">>(
|
|
93
|
+
reference: Q,
|
|
94
|
+
args: FunctionArgs<Q>,
|
|
95
|
+
): Promise<FunctionReturnType<Q>>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface RunMutationCtx {
|
|
99
|
+
runMutation<M extends FunctionReference<"mutation", "internal">>(
|
|
100
|
+
reference: M,
|
|
101
|
+
args: FunctionArgs<M>,
|
|
102
|
+
): Promise<FunctionReturnType<M>>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Consumer-facing client for the flat ReBAC relationship graph. The host owns
|
|
107
|
+
* identity, the rich entity, and auth; it passes opaque `memberRef` /
|
|
108
|
+
* `resourceRef` strings and an optional `relation` into the client.
|
|
109
|
+
*/
|
|
110
|
+
export class Memberships {
|
|
111
|
+
private readonly defaultRelation: string;
|
|
112
|
+
private readonly defaultMemberKind: MemberKind;
|
|
113
|
+
|
|
114
|
+
constructor(
|
|
115
|
+
private readonly component: MembershipsComponent,
|
|
116
|
+
options: MembershipsOptions = {},
|
|
117
|
+
) {
|
|
118
|
+
this.defaultRelation = options.defaultRelation ?? DEFAULT_RELATION;
|
|
119
|
+
this.defaultMemberKind = options.defaultMemberKind ?? DEFAULT_MEMBER_KIND;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
private relationOf(relation: string | undefined): string {
|
|
123
|
+
return relation ?? this.defaultRelation;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private kindOf(kind: MemberKind | undefined): MemberKind {
|
|
127
|
+
return kind ?? this.defaultMemberKind;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Add the edge `(memberRef, resourceRef, relation)`, classified by
|
|
132
|
+
* `memberKind` and optionally stamped with an opaque `status`. Idempotent —
|
|
133
|
+
* returns the existing id if the exact tuple is already held.
|
|
134
|
+
*/
|
|
135
|
+
add(
|
|
136
|
+
ctx: RunMutationCtx,
|
|
137
|
+
memberRef: string,
|
|
138
|
+
resourceRef: string,
|
|
139
|
+
relation?: string,
|
|
140
|
+
memberKind?: MemberKind,
|
|
141
|
+
status?: string,
|
|
142
|
+
): Promise<string> {
|
|
143
|
+
return ctx.runMutation(this.component.mutations.add, {
|
|
144
|
+
memberRef,
|
|
145
|
+
memberKind: this.kindOf(memberKind),
|
|
146
|
+
resourceRef,
|
|
147
|
+
relation: this.relationOf(relation),
|
|
148
|
+
status,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Remove the edge `(memberRef, resourceRef, relation)`. Idempotent — returns
|
|
154
|
+
* `{ removed: false }` when the edge was absent, `{ removed: true }` otherwise.
|
|
155
|
+
*/
|
|
156
|
+
remove(
|
|
157
|
+
ctx: RunMutationCtx,
|
|
158
|
+
memberRef: string,
|
|
159
|
+
resourceRef: string,
|
|
160
|
+
relation?: string,
|
|
161
|
+
): Promise<RemoveResult> {
|
|
162
|
+
return ctx.runMutation(this.component.mutations.remove, {
|
|
163
|
+
memberRef,
|
|
164
|
+
resourceRef,
|
|
165
|
+
relation: this.relationOf(relation),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Change a member's relation on a resource from `fromRelation` to `toRelation`. */
|
|
170
|
+
setRelation(
|
|
171
|
+
ctx: RunMutationCtx,
|
|
172
|
+
memberRef: string,
|
|
173
|
+
resourceRef: string,
|
|
174
|
+
fromRelation: string,
|
|
175
|
+
toRelation: string,
|
|
176
|
+
): Promise<SetRelationResult> {
|
|
177
|
+
return ctx.runMutation(this.component.mutations.setRelation, {
|
|
178
|
+
memberRef,
|
|
179
|
+
resourceRef,
|
|
180
|
+
fromRelation,
|
|
181
|
+
toRelation,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* One page of members of `resourceRef`, optionally filtered to a single
|
|
187
|
+
* `relation`. Pass `paginationOpts` (`{ numItems, cursor }`); feed the
|
|
188
|
+
* returned `continueCursor` back to load the next page.
|
|
189
|
+
*/
|
|
190
|
+
listMembers(
|
|
191
|
+
ctx: RunQueryCtx,
|
|
192
|
+
resourceRef: string,
|
|
193
|
+
paginationOpts: PaginationOptions,
|
|
194
|
+
relation?: string,
|
|
195
|
+
): Promise<Page<MemberEntry>> {
|
|
196
|
+
return ctx.runQuery(this.component.queries.listMembers, {
|
|
197
|
+
resourceRef,
|
|
198
|
+
relation,
|
|
199
|
+
paginationOpts,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** One page of resources that `memberRef` relates to, with each relation. */
|
|
204
|
+
members(
|
|
205
|
+
ctx: RunQueryCtx,
|
|
206
|
+
memberRef: string,
|
|
207
|
+
paginationOpts: PaginationOptions,
|
|
208
|
+
): Promise<Page<ResourceEntry>> {
|
|
209
|
+
return ctx.runQuery(this.component.queries.members, {
|
|
210
|
+
memberRef,
|
|
211
|
+
paginationOpts,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Whether `memberRef` relates to `resourceRef`. With `relation`, checks that
|
|
217
|
+
* exact edge; without, checks any relation between the two.
|
|
218
|
+
*
|
|
219
|
+
* @remarks
|
|
220
|
+
* **Security warning — unscoped path.** When `relation` is omitted this
|
|
221
|
+
* method returns `true` for **any** relation stored between the pair
|
|
222
|
+
* (e.g. `"invited"`, `"suspended"`, `"banned"`). Do **not** use the
|
|
223
|
+
* unscoped path as an authorization gate without first enumerating every
|
|
224
|
+
* relation your policy considers sufficient for the guarded action. Use the
|
|
225
|
+
* scoped path (`relation` provided) for authz checks, or enumerate
|
|
226
|
+
* acceptable relations explicitly before calling.
|
|
227
|
+
*/
|
|
228
|
+
isMember(
|
|
229
|
+
ctx: RunQueryCtx,
|
|
230
|
+
memberRef: string,
|
|
231
|
+
resourceRef: string,
|
|
232
|
+
relation?: string,
|
|
233
|
+
): Promise<boolean> {
|
|
234
|
+
return ctx.runQuery(this.component.queries.isMember, {
|
|
235
|
+
memberRef,
|
|
236
|
+
resourceRef,
|
|
237
|
+
relation,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* One page of full membership docs (`memberRef`, `memberKind`, `resourceRef`,
|
|
243
|
+
* `relation`, `status?`, `createdAt`). Optionally scoped by `resourceRef` or
|
|
244
|
+
* `memberRef` (resource wins if both are given); unscoped paginates all edges.
|
|
245
|
+
*/
|
|
246
|
+
documents(
|
|
247
|
+
ctx: RunQueryCtx,
|
|
248
|
+
paginationOpts: PaginationOptions,
|
|
249
|
+
filter: { resourceRef?: string; memberRef?: string } = {},
|
|
250
|
+
): Promise<Page<MembershipDoc>> {
|
|
251
|
+
return ctx.runQuery(this.component.queries.documents, {
|
|
252
|
+
resourceRef: filter.resourceRef,
|
|
253
|
+
memberRef: filter.memberRef,
|
|
254
|
+
paginationOpts,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export type {
|
|
260
|
+
MemberEntry,
|
|
261
|
+
MemberKind,
|
|
262
|
+
MembershipDoc,
|
|
263
|
+
MembershipsOptions,
|
|
264
|
+
Page,
|
|
265
|
+
PaginationOptions,
|
|
266
|
+
RemoveResult,
|
|
267
|
+
ResourceEntry,
|
|
268
|
+
SetRelationReason,
|
|
269
|
+
SetRelationResult,
|
|
270
|
+
} from "./types.js";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** Public TypeScript surface for the memberships client. */
|
|
2
|
+
|
|
3
|
+
import type { PaginationOptions, PaginationResult } from "convex/server";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What a tuple's member points at — an opaque, host-classified string
|
|
7
|
+
* (e.g. `"user"`, `"group"`, `"resource"`, or any host-defined kind).
|
|
8
|
+
*/
|
|
9
|
+
export type MemberKind = string;
|
|
10
|
+
|
|
11
|
+
/** A member of a resource, as returned by {@link Memberships.listMembers}. */
|
|
12
|
+
export interface MemberEntry {
|
|
13
|
+
memberRef: string;
|
|
14
|
+
memberKind: MemberKind;
|
|
15
|
+
relation: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A resource a member relates to, as returned by {@link Memberships.members}. */
|
|
19
|
+
export interface ResourceEntry {
|
|
20
|
+
resourceRef: string;
|
|
21
|
+
relation: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A full membership edge, as returned by {@link Memberships.documents}. */
|
|
25
|
+
export interface MembershipDoc {
|
|
26
|
+
memberRef: string;
|
|
27
|
+
memberKind: MemberKind;
|
|
28
|
+
resourceRef: string;
|
|
29
|
+
relation: string;
|
|
30
|
+
/** Opaque host-stamped lifecycle marker, if any. */
|
|
31
|
+
status?: string;
|
|
32
|
+
/** Epoch milliseconds the edge was first inserted. */
|
|
33
|
+
createdAt: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Stable code-tag explaining why a {@link Memberships.setRelation} was rejected. */
|
|
37
|
+
export type SetRelationReason = "NOT_FOUND" | "EXISTS";
|
|
38
|
+
|
|
39
|
+
/** Result of {@link Memberships.setRelation} — may be rejected. */
|
|
40
|
+
export interface SetRelationResult {
|
|
41
|
+
ok: boolean;
|
|
42
|
+
/** Stable code-tag when `ok` is false. */
|
|
43
|
+
reason?: SetRelationReason;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Result of {@link Memberships.remove} — `removed` is true if an edge was deleted. */
|
|
47
|
+
export interface RemoveResult {
|
|
48
|
+
removed: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A page of results, mirroring Convex's `PaginationResult`. `continueCursor`
|
|
53
|
+
* feeds the next call's `paginationOpts.cursor`; `isDone` is true on the last page.
|
|
54
|
+
*/
|
|
55
|
+
export type Page<T> = Pick<
|
|
56
|
+
PaginationResult<T>,
|
|
57
|
+
"page" | "isDone" | "continueCursor"
|
|
58
|
+
>;
|
|
59
|
+
|
|
60
|
+
/** Pagination options, as accepted by the paginated client methods. */
|
|
61
|
+
export type { PaginationOptions };
|
|
62
|
+
|
|
63
|
+
/** Construction options for the {@link Memberships} client. */
|
|
64
|
+
export interface MembershipsOptions {
|
|
65
|
+
/** Relation applied when a call omits `relation`. Default `"member"`. */
|
|
66
|
+
defaultRelation?: string;
|
|
67
|
+
/** Member kind applied when a call omits `memberKind`. Default `"user"`. */
|
|
68
|
+
defaultMemberKind?: MemberKind;
|
|
69
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated `api` utility.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type * as mutations from "../mutations.js";
|
|
12
|
+
import type * as queries from "../queries.js";
|
|
13
|
+
import type * as validators from "../validators.js";
|
|
14
|
+
|
|
15
|
+
import type {
|
|
16
|
+
ApiFromModules,
|
|
17
|
+
FilterApi,
|
|
18
|
+
FunctionReference,
|
|
19
|
+
} from "convex/server";
|
|
20
|
+
import { anyApi, componentsGeneric } from "convex/server";
|
|
21
|
+
|
|
22
|
+
const fullApi: ApiFromModules<{
|
|
23
|
+
mutations: typeof mutations;
|
|
24
|
+
queries: typeof queries;
|
|
25
|
+
validators: typeof validators;
|
|
26
|
+
}> = anyApi as any;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
30
|
+
*
|
|
31
|
+
* Usage:
|
|
32
|
+
* ```js
|
|
33
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export const api: FilterApi<
|
|
37
|
+
typeof fullApi,
|
|
38
|
+
FunctionReference<any, "public">
|
|
39
|
+
> = anyApi as any;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
43
|
+
*
|
|
44
|
+
* Usage:
|
|
45
|
+
* ```js
|
|
46
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export const internal: FilterApi<
|
|
50
|
+
typeof fullApi,
|
|
51
|
+
FunctionReference<any, "internal">
|
|
52
|
+
> = anyApi as any;
|
|
53
|
+
|
|
54
|
+
export const components = componentsGeneric() as unknown as {};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated `ComponentApi` utility.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { FunctionReference } from "convex/server";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A utility for referencing a Convex component's exposed API.
|
|
15
|
+
*
|
|
16
|
+
* Useful when expecting a parameter like `components.myComponent`.
|
|
17
|
+
* Usage:
|
|
18
|
+
* ```ts
|
|
19
|
+
* async function myFunction(ctx: QueryCtx, component: ComponentApi) {
|
|
20
|
+
* return ctx.runQuery(component.someFile.someQuery, { ...args });
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
25
|
+
{
|
|
26
|
+
mutations: {
|
|
27
|
+
add: FunctionReference<
|
|
28
|
+
"mutation",
|
|
29
|
+
"internal",
|
|
30
|
+
{
|
|
31
|
+
memberKind: string;
|
|
32
|
+
memberRef: string;
|
|
33
|
+
relation: string;
|
|
34
|
+
resourceRef: string;
|
|
35
|
+
status?: string;
|
|
36
|
+
},
|
|
37
|
+
string,
|
|
38
|
+
Name
|
|
39
|
+
>;
|
|
40
|
+
remove: FunctionReference<
|
|
41
|
+
"mutation",
|
|
42
|
+
"internal",
|
|
43
|
+
{ memberRef: string; relation: string; resourceRef: string },
|
|
44
|
+
{ removed: boolean },
|
|
45
|
+
Name
|
|
46
|
+
>;
|
|
47
|
+
setRelation: FunctionReference<
|
|
48
|
+
"mutation",
|
|
49
|
+
"internal",
|
|
50
|
+
{
|
|
51
|
+
fromRelation: string;
|
|
52
|
+
memberRef: string;
|
|
53
|
+
resourceRef: string;
|
|
54
|
+
toRelation: string;
|
|
55
|
+
},
|
|
56
|
+
{ ok: boolean; reason?: "NOT_FOUND" | "EXISTS" },
|
|
57
|
+
Name
|
|
58
|
+
>;
|
|
59
|
+
};
|
|
60
|
+
queries: {
|
|
61
|
+
documents: FunctionReference<
|
|
62
|
+
"query",
|
|
63
|
+
"internal",
|
|
64
|
+
{
|
|
65
|
+
memberRef?: string;
|
|
66
|
+
paginationOpts: {
|
|
67
|
+
cursor: string | null;
|
|
68
|
+
endCursor?: string | null;
|
|
69
|
+
id?: number;
|
|
70
|
+
maximumBytesRead?: number;
|
|
71
|
+
maximumRowsRead?: number;
|
|
72
|
+
numItems: number;
|
|
73
|
+
};
|
|
74
|
+
resourceRef?: string;
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
continueCursor: string;
|
|
78
|
+
isDone: boolean;
|
|
79
|
+
page: Array<{
|
|
80
|
+
createdAt: number;
|
|
81
|
+
memberKind: string;
|
|
82
|
+
memberRef: string;
|
|
83
|
+
relation: string;
|
|
84
|
+
resourceRef: string;
|
|
85
|
+
status?: string;
|
|
86
|
+
}>;
|
|
87
|
+
},
|
|
88
|
+
Name
|
|
89
|
+
>;
|
|
90
|
+
isMember: FunctionReference<
|
|
91
|
+
"query",
|
|
92
|
+
"internal",
|
|
93
|
+
{ memberRef: string; relation?: string; resourceRef: string },
|
|
94
|
+
boolean,
|
|
95
|
+
Name
|
|
96
|
+
>;
|
|
97
|
+
listMembers: FunctionReference<
|
|
98
|
+
"query",
|
|
99
|
+
"internal",
|
|
100
|
+
{
|
|
101
|
+
paginationOpts: {
|
|
102
|
+
cursor: string | null;
|
|
103
|
+
endCursor?: string | null;
|
|
104
|
+
id?: number;
|
|
105
|
+
maximumBytesRead?: number;
|
|
106
|
+
maximumRowsRead?: number;
|
|
107
|
+
numItems: number;
|
|
108
|
+
};
|
|
109
|
+
relation?: string;
|
|
110
|
+
resourceRef: string;
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
continueCursor: string;
|
|
114
|
+
isDone: boolean;
|
|
115
|
+
page: Array<{
|
|
116
|
+
memberKind: string;
|
|
117
|
+
memberRef: string;
|
|
118
|
+
relation: string;
|
|
119
|
+
}>;
|
|
120
|
+
},
|
|
121
|
+
Name
|
|
122
|
+
>;
|
|
123
|
+
members: FunctionReference<
|
|
124
|
+
"query",
|
|
125
|
+
"internal",
|
|
126
|
+
{
|
|
127
|
+
memberRef: string;
|
|
128
|
+
paginationOpts: {
|
|
129
|
+
cursor: string | null;
|
|
130
|
+
endCursor?: string | null;
|
|
131
|
+
id?: number;
|
|
132
|
+
maximumBytesRead?: number;
|
|
133
|
+
maximumRowsRead?: number;
|
|
134
|
+
numItems: number;
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
continueCursor: string;
|
|
139
|
+
isDone: boolean;
|
|
140
|
+
page: Array<{ relation: string; resourceRef: string }>;
|
|
141
|
+
},
|
|
142
|
+
Name
|
|
143
|
+
>;
|
|
144
|
+
};
|
|
145
|
+
};
|