@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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bntvllnt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<!-- Badges -->
|
|
2
|
+
[](https://www.convex.dev/components)
|
|
3
|
+
[](https://www.npmjs.com/package/@vllnt/convex-memberships)
|
|
4
|
+
[](https://github.com/vllnt/convex-memberships/actions/workflows/ci.yml)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
|
|
7
|
+
# @vllnt/convex-memberships
|
|
8
|
+
|
|
9
|
+
Auth-agnostic membership and relationship graph (ReBAC tuples), as a Convex
|
|
10
|
+
component.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
const memberships = new Memberships(components.memberships);
|
|
14
|
+
await memberships.add(ctx, userId, orgId, "admin");
|
|
15
|
+
const isAdmin = await memberships.isMember(ctx, userId, orgId, "admin");
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
A tuple is `(memberRef, resourceRef, relation)`, classified by an opaque
|
|
19
|
+
`memberKind`. Domain-neutral: org membership, document sharing, team roles, group
|
|
20
|
+
nesting — any "who relates to what, and how" question. Edges are **flat** —
|
|
21
|
+
transitive expansion (a member of a group that is a member of an org) is **not**
|
|
22
|
+
auto-resolved; it is planned for vNext.
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- **Flat ReBAC tuples** — `(memberRef, resourceRef, relation)` with an opaque `memberKind` (defaults `"user"`) and optional `status`.
|
|
27
|
+
- **Idempotent edges** — `add` dedupes on the full tuple, returning the existing id and patching `memberKind` / `status`.
|
|
28
|
+
- **Paginated listing** — members of a resource, and resources of a member, both paginated for guild/workspace scale.
|
|
29
|
+
- **Relation filtering** — list members narrowed to a single relation.
|
|
30
|
+
- **Bounded membership checks** — exact-relation, or any-relation via index (not a full member scan).
|
|
31
|
+
- **Guarded relation transitions** — `setRelation` moves an edge, guarded against collisions; missing source ⇒ `NOT_FOUND`.
|
|
32
|
+
- **Auditable removal** — `remove` returns `{ removed }`; `documents` exposes stored `createdAt` and `status`.
|
|
33
|
+
- **Opaque refs** — every ref/relation/kind/status is an arbitrary host string the component never inspects.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pnpm add @vllnt/convex-memberships
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Peer dependency: `convex@^1.41.0`.
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
// convex/convex.config.ts
|
|
47
|
+
import { defineApp } from "convex/server";
|
|
48
|
+
import memberships from "@vllnt/convex-memberships/convex.config";
|
|
49
|
+
|
|
50
|
+
const app = defineApp();
|
|
51
|
+
app.use(memberships);
|
|
52
|
+
export default app;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
// convex/teams.ts — host owns auth; pass opaque refs in.
|
|
57
|
+
import { components } from "./_generated/api";
|
|
58
|
+
import { mutation, query } from "./_generated/server";
|
|
59
|
+
import { v } from "convex/values";
|
|
60
|
+
import { Memberships } from "@vllnt/convex-memberships";
|
|
61
|
+
|
|
62
|
+
const memberships = new Memberships(components.memberships);
|
|
63
|
+
|
|
64
|
+
export const join = mutation({
|
|
65
|
+
args: { userId: v.string(), orgId: v.string() },
|
|
66
|
+
handler: (ctx, { userId, orgId }) => memberships.add(ctx, userId, orgId),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export const isInOrg = query({
|
|
70
|
+
args: { userId: v.string(), orgId: v.string() },
|
|
71
|
+
handler: (ctx, { userId, orgId }) => memberships.isMember(ctx, userId, orgId),
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Client options: `new Memberships(component, { defaultRelation = "member", defaultMemberKind = "user" })`.
|
|
76
|
+
|
|
77
|
+
## API Reference
|
|
78
|
+
|
|
79
|
+
| Method | Kind | Result |
|
|
80
|
+
|--------|------|--------|
|
|
81
|
+
| `add(ctx, memberRef, resourceRef, relation?, memberKind?, status?)` | mutation | `id` (tuple-idempotent; patches `memberKind`/`status` on re-add) |
|
|
82
|
+
| `remove(ctx, memberRef, resourceRef, relation?)` | mutation | `{ removed }` (idempotent) |
|
|
83
|
+
| `setRelation(ctx, memberRef, resourceRef, fromRelation, toRelation)` | mutation | `{ ok, reason? }` (`NOT_FOUND` \| `EXISTS`) |
|
|
84
|
+
| `listMembers(ctx, resourceRef, paginationOpts, relation?)` | query | `Page<MemberEntry>` |
|
|
85
|
+
| `members(ctx, memberRef, paginationOpts)` | query | `Page<ResourceEntry>` |
|
|
86
|
+
| `isMember(ctx, memberRef, resourceRef, relation?)` | query | `boolean` |
|
|
87
|
+
| `documents(ctx, paginationOpts, filter?)` | query | `Page<MembershipDoc>` |
|
|
88
|
+
|
|
89
|
+
Full reference: [docs/API.md](docs/API.md).
|
|
90
|
+
|
|
91
|
+
## React
|
|
92
|
+
|
|
93
|
+
An optional, tree-shakeable `./react` entry ships thin hooks over `convex/react`'s
|
|
94
|
+
`useQuery`. `react` is an optional peer dependency — a backend-only consumer pulls
|
|
95
|
+
zero React. Each hook takes the host app's re-exported query reference.
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
import { useIsMember } from "@vllnt/convex-memberships/react";
|
|
99
|
+
import { api } from "../convex/_generated/api";
|
|
100
|
+
|
|
101
|
+
const isAdmin = useIsMember(api.memberships.isMember, {
|
|
102
|
+
memberRef: userId,
|
|
103
|
+
resourceRef: orgId,
|
|
104
|
+
relation: "admin",
|
|
105
|
+
}); // boolean | undefined (undefined while loading)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
| Hook | Args | Returns |
|
|
109
|
+
|------|------|---------|
|
|
110
|
+
| `useIsMember(isMemberRef, { memberRef, resourceRef, relation? })` | the host's `isMember` ref | `boolean \| undefined` |
|
|
111
|
+
| `useMembers(membersRef, { memberRef })` | the host's `members` ref | first page of resource entries `\| undefined` |
|
|
112
|
+
| `useListMembers(listMembersRef, { resourceRef, relation? })` | the host's `listMembers` ref | first page of member entries `\| undefined` |
|
|
113
|
+
|
|
114
|
+
## Security
|
|
115
|
+
|
|
116
|
+
- **Auth-agnostic** — the host resolves identity, decides who may create/read an edge, and passes opaque refs; tables are sandboxed (reached only via the client).
|
|
117
|
+
- **`isMember` footgun** — called without `relation`, it returns `true` for **any** stored relation (`"invited"`, `"suspended"`, `"banned"`, …). For authz gates, always pass `relation` or enumerate the relations your policy accepts.
|
|
118
|
+
|
|
119
|
+
See [docs/API.md](docs/API.md).
|
|
120
|
+
|
|
121
|
+
## Testing
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
pnpm test # single run
|
|
125
|
+
pnpm test:coverage # enforced 100% on covered files
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Tests run against the real component runtime via `convex-test` (`@edge-runtime/vm`), not mocks.
|
|
129
|
+
|
|
130
|
+
## Contributing
|
|
131
|
+
|
|
132
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
133
|
+
|
|
134
|
+
## Author
|
|
135
|
+
|
|
136
|
+
Built by [bntvllnt](https://github.com/bntvllnt) · [bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
|
|
137
|
+
|
|
138
|
+
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet — [vllnt.com](https://vllnt.com)
|
|
139
|
+
|
|
140
|
+
If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { FunctionArgs, FunctionReference, FunctionReturnType, PaginationOptions } from "convex/server";
|
|
2
|
+
import type { MemberEntry, MemberKind, MembershipDoc, MembershipsOptions, Page, RemoveResult, ResourceEntry, SetRelationResult } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The memberships component's function references, as exposed on the host via
|
|
5
|
+
* `components.memberships`.
|
|
6
|
+
*/
|
|
7
|
+
export interface MembershipsComponent {
|
|
8
|
+
mutations: {
|
|
9
|
+
add: FunctionReference<"mutation", "internal", {
|
|
10
|
+
memberRef: string;
|
|
11
|
+
memberKind: MemberKind;
|
|
12
|
+
resourceRef: string;
|
|
13
|
+
relation: string;
|
|
14
|
+
status?: string;
|
|
15
|
+
}, string>;
|
|
16
|
+
remove: FunctionReference<"mutation", "internal", {
|
|
17
|
+
memberRef: string;
|
|
18
|
+
resourceRef: string;
|
|
19
|
+
relation: string;
|
|
20
|
+
}, RemoveResult>;
|
|
21
|
+
setRelation: FunctionReference<"mutation", "internal", {
|
|
22
|
+
memberRef: string;
|
|
23
|
+
resourceRef: string;
|
|
24
|
+
fromRelation: string;
|
|
25
|
+
toRelation: string;
|
|
26
|
+
}, SetRelationResult>;
|
|
27
|
+
};
|
|
28
|
+
queries: {
|
|
29
|
+
listMembers: FunctionReference<"query", "internal", {
|
|
30
|
+
resourceRef: string;
|
|
31
|
+
relation?: string;
|
|
32
|
+
paginationOpts: PaginationOptions;
|
|
33
|
+
}, Page<MemberEntry>>;
|
|
34
|
+
members: FunctionReference<"query", "internal", {
|
|
35
|
+
memberRef: string;
|
|
36
|
+
paginationOpts: PaginationOptions;
|
|
37
|
+
}, Page<ResourceEntry>>;
|
|
38
|
+
isMember: FunctionReference<"query", "internal", {
|
|
39
|
+
memberRef: string;
|
|
40
|
+
resourceRef: string;
|
|
41
|
+
relation?: string;
|
|
42
|
+
}, boolean>;
|
|
43
|
+
documents: FunctionReference<"query", "internal", {
|
|
44
|
+
resourceRef?: string;
|
|
45
|
+
memberRef?: string;
|
|
46
|
+
paginationOpts: PaginationOptions;
|
|
47
|
+
}, Page<MembershipDoc>>;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
interface RunQueryCtx {
|
|
51
|
+
runQuery<Q extends FunctionReference<"query", "internal">>(reference: Q, args: FunctionArgs<Q>): Promise<FunctionReturnType<Q>>;
|
|
52
|
+
}
|
|
53
|
+
interface RunMutationCtx {
|
|
54
|
+
runMutation<M extends FunctionReference<"mutation", "internal">>(reference: M, args: FunctionArgs<M>): Promise<FunctionReturnType<M>>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Consumer-facing client for the flat ReBAC relationship graph. The host owns
|
|
58
|
+
* identity, the rich entity, and auth; it passes opaque `memberRef` /
|
|
59
|
+
* `resourceRef` strings and an optional `relation` into the client.
|
|
60
|
+
*/
|
|
61
|
+
export declare class Memberships {
|
|
62
|
+
private readonly component;
|
|
63
|
+
private readonly defaultRelation;
|
|
64
|
+
private readonly defaultMemberKind;
|
|
65
|
+
constructor(component: MembershipsComponent, options?: MembershipsOptions);
|
|
66
|
+
private relationOf;
|
|
67
|
+
private kindOf;
|
|
68
|
+
/**
|
|
69
|
+
* Add the edge `(memberRef, resourceRef, relation)`, classified by
|
|
70
|
+
* `memberKind` and optionally stamped with an opaque `status`. Idempotent —
|
|
71
|
+
* returns the existing id if the exact tuple is already held.
|
|
72
|
+
*/
|
|
73
|
+
add(ctx: RunMutationCtx, memberRef: string, resourceRef: string, relation?: string, memberKind?: MemberKind, status?: string): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Remove the edge `(memberRef, resourceRef, relation)`. Idempotent — returns
|
|
76
|
+
* `{ removed: false }` when the edge was absent, `{ removed: true }` otherwise.
|
|
77
|
+
*/
|
|
78
|
+
remove(ctx: RunMutationCtx, memberRef: string, resourceRef: string, relation?: string): Promise<RemoveResult>;
|
|
79
|
+
/** Change a member's relation on a resource from `fromRelation` to `toRelation`. */
|
|
80
|
+
setRelation(ctx: RunMutationCtx, memberRef: string, resourceRef: string, fromRelation: string, toRelation: string): Promise<SetRelationResult>;
|
|
81
|
+
/**
|
|
82
|
+
* One page of members of `resourceRef`, optionally filtered to a single
|
|
83
|
+
* `relation`. Pass `paginationOpts` (`{ numItems, cursor }`); feed the
|
|
84
|
+
* returned `continueCursor` back to load the next page.
|
|
85
|
+
*/
|
|
86
|
+
listMembers(ctx: RunQueryCtx, resourceRef: string, paginationOpts: PaginationOptions, relation?: string): Promise<Page<MemberEntry>>;
|
|
87
|
+
/** One page of resources that `memberRef` relates to, with each relation. */
|
|
88
|
+
members(ctx: RunQueryCtx, memberRef: string, paginationOpts: PaginationOptions): Promise<Page<ResourceEntry>>;
|
|
89
|
+
/**
|
|
90
|
+
* Whether `memberRef` relates to `resourceRef`. With `relation`, checks that
|
|
91
|
+
* exact edge; without, checks any relation between the two.
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* **Security warning — unscoped path.** When `relation` is omitted this
|
|
95
|
+
* method returns `true` for **any** relation stored between the pair
|
|
96
|
+
* (e.g. `"invited"`, `"suspended"`, `"banned"`). Do **not** use the
|
|
97
|
+
* unscoped path as an authorization gate without first enumerating every
|
|
98
|
+
* relation your policy considers sufficient for the guarded action. Use the
|
|
99
|
+
* scoped path (`relation` provided) for authz checks, or enumerate
|
|
100
|
+
* acceptable relations explicitly before calling.
|
|
101
|
+
*/
|
|
102
|
+
isMember(ctx: RunQueryCtx, memberRef: string, resourceRef: string, relation?: string): Promise<boolean>;
|
|
103
|
+
/**
|
|
104
|
+
* One page of full membership docs (`memberRef`, `memberKind`, `resourceRef`,
|
|
105
|
+
* `relation`, `status?`, `createdAt`). Optionally scoped by `resourceRef` or
|
|
106
|
+
* `memberRef` (resource wins if both are given); unscoped paginates all edges.
|
|
107
|
+
*/
|
|
108
|
+
documents(ctx: RunQueryCtx, paginationOpts: PaginationOptions, filter?: {
|
|
109
|
+
resourceRef?: string;
|
|
110
|
+
memberRef?: string;
|
|
111
|
+
}): Promise<Page<MembershipDoc>>;
|
|
112
|
+
}
|
|
113
|
+
export type { MemberEntry, MemberKind, MembershipDoc, MembershipsOptions, Page, PaginationOptions, RemoveResult, ResourceEntry, SetRelationReason, SetRelationResult, } from "./types.js";
|
|
114
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,IAAI,EACJ,YAAY,EACZ,aAAa,EACb,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAGpB;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE;QACT,GAAG,EAAE,iBAAiB,CACpB,UAAU,EACV,UAAU,EACV;YACE,SAAS,EAAE,MAAM,CAAC;YAClB,UAAU,EAAE,UAAU,CAAC;YACvB,WAAW,EAAE,MAAM,CAAC;YACpB,QAAQ,EAAE,MAAM,CAAC;YACjB,MAAM,CAAC,EAAE,MAAM,CAAC;SACjB,EACD,MAAM,CACP,CAAC;QACF,MAAM,EAAE,iBAAiB,CACvB,UAAU,EACV,UAAU,EACV;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,WAAW,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,EAC5D,YAAY,CACb,CAAC;QACF,WAAW,EAAE,iBAAiB,CAC5B,UAAU,EACV,UAAU,EACV;YACE,SAAS,EAAE,MAAM,CAAC;YAClB,WAAW,EAAE,MAAM,CAAC;YACpB,YAAY,EAAE,MAAM,CAAC;YACrB,UAAU,EAAE,MAAM,CAAC;SACpB,EACD,iBAAiB,CAClB,CAAC;KACH,CAAC;IACF,OAAO,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AM,EACnB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC;IAQnB;;;;OAIG;IACH,SAAS,CACP,GAAG,EAAE,WAAW,EAChB,cAAc,EAAE,iBAAiB,EACjC,MAAM,GAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GACxD,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;CAOhC;AAED,YAAY,EACV,WAAW,EACX,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,IAAI,EACJ,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { DEFAULT_MEMBER_KIND, DEFAULT_RELATION } from "../shared.js";
|
|
2
|
+
/**
|
|
3
|
+
* Consumer-facing client for the flat ReBAC relationship graph. The host owns
|
|
4
|
+
* identity, the rich entity, and auth; it passes opaque `memberRef` /
|
|
5
|
+
* `resourceRef` strings and an optional `relation` into the client.
|
|
6
|
+
*/
|
|
7
|
+
export class Memberships {
|
|
8
|
+
component;
|
|
9
|
+
defaultRelation;
|
|
10
|
+
defaultMemberKind;
|
|
11
|
+
constructor(component, options = {}) {
|
|
12
|
+
this.component = component;
|
|
13
|
+
this.defaultRelation = options.defaultRelation ?? DEFAULT_RELATION;
|
|
14
|
+
this.defaultMemberKind = options.defaultMemberKind ?? DEFAULT_MEMBER_KIND;
|
|
15
|
+
}
|
|
16
|
+
relationOf(relation) {
|
|
17
|
+
return relation ?? this.defaultRelation;
|
|
18
|
+
}
|
|
19
|
+
kindOf(kind) {
|
|
20
|
+
return kind ?? this.defaultMemberKind;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Add the edge `(memberRef, resourceRef, relation)`, classified by
|
|
24
|
+
* `memberKind` and optionally stamped with an opaque `status`. Idempotent —
|
|
25
|
+
* returns the existing id if the exact tuple is already held.
|
|
26
|
+
*/
|
|
27
|
+
add(ctx, memberRef, resourceRef, relation, memberKind, status) {
|
|
28
|
+
return ctx.runMutation(this.component.mutations.add, {
|
|
29
|
+
memberRef,
|
|
30
|
+
memberKind: this.kindOf(memberKind),
|
|
31
|
+
resourceRef,
|
|
32
|
+
relation: this.relationOf(relation),
|
|
33
|
+
status,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Remove the edge `(memberRef, resourceRef, relation)`. Idempotent — returns
|
|
38
|
+
* `{ removed: false }` when the edge was absent, `{ removed: true }` otherwise.
|
|
39
|
+
*/
|
|
40
|
+
remove(ctx, memberRef, resourceRef, relation) {
|
|
41
|
+
return ctx.runMutation(this.component.mutations.remove, {
|
|
42
|
+
memberRef,
|
|
43
|
+
resourceRef,
|
|
44
|
+
relation: this.relationOf(relation),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** Change a member's relation on a resource from `fromRelation` to `toRelation`. */
|
|
48
|
+
setRelation(ctx, memberRef, resourceRef, fromRelation, toRelation) {
|
|
49
|
+
return ctx.runMutation(this.component.mutations.setRelation, {
|
|
50
|
+
memberRef,
|
|
51
|
+
resourceRef,
|
|
52
|
+
fromRelation,
|
|
53
|
+
toRelation,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* One page of members of `resourceRef`, optionally filtered to a single
|
|
58
|
+
* `relation`. Pass `paginationOpts` (`{ numItems, cursor }`); feed the
|
|
59
|
+
* returned `continueCursor` back to load the next page.
|
|
60
|
+
*/
|
|
61
|
+
listMembers(ctx, resourceRef, paginationOpts, relation) {
|
|
62
|
+
return ctx.runQuery(this.component.queries.listMembers, {
|
|
63
|
+
resourceRef,
|
|
64
|
+
relation,
|
|
65
|
+
paginationOpts,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/** One page of resources that `memberRef` relates to, with each relation. */
|
|
69
|
+
members(ctx, memberRef, paginationOpts) {
|
|
70
|
+
return ctx.runQuery(this.component.queries.members, {
|
|
71
|
+
memberRef,
|
|
72
|
+
paginationOpts,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Whether `memberRef` relates to `resourceRef`. With `relation`, checks that
|
|
77
|
+
* exact edge; without, checks any relation between the two.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* **Security warning — unscoped path.** When `relation` is omitted this
|
|
81
|
+
* method returns `true` for **any** relation stored between the pair
|
|
82
|
+
* (e.g. `"invited"`, `"suspended"`, `"banned"`). Do **not** use the
|
|
83
|
+
* unscoped path as an authorization gate without first enumerating every
|
|
84
|
+
* relation your policy considers sufficient for the guarded action. Use the
|
|
85
|
+
* scoped path (`relation` provided) for authz checks, or enumerate
|
|
86
|
+
* acceptable relations explicitly before calling.
|
|
87
|
+
*/
|
|
88
|
+
isMember(ctx, memberRef, resourceRef, relation) {
|
|
89
|
+
return ctx.runQuery(this.component.queries.isMember, {
|
|
90
|
+
memberRef,
|
|
91
|
+
resourceRef,
|
|
92
|
+
relation,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* One page of full membership docs (`memberRef`, `memberKind`, `resourceRef`,
|
|
97
|
+
* `relation`, `status?`, `createdAt`). Optionally scoped by `resourceRef` or
|
|
98
|
+
* `memberRef` (resource wins if both are given); unscoped paginates all edges.
|
|
99
|
+
*/
|
|
100
|
+
documents(ctx, paginationOpts, filter = {}) {
|
|
101
|
+
return ctx.runQuery(this.component.queries.documents, {
|
|
102
|
+
resourceRef: filter.resourceRef,
|
|
103
|
+
memberRef: filter.memberRef,
|
|
104
|
+
paginationOpts,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"A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EACjB,WAAmB,EACnB,YAAoB,EACpB,UAAkB;QAElB,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE;YAC3D,SAAS;YACT,WAAW;YACX,YAAY;YACZ,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,WAAW,CACT,GAAgB,EAChB,WAAmB,EACnB,cAAiC,EACjC,QAAiB;QAEjB,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,WAAW,EAAE;YACtD,WAAW;YACX,QAAQ;YACR,cAAc;SACf,CAAC,CAAC;IACL,CAAC;IAED,6EAA6E;IAC7E,OAAO,CACL,GAAgB,EAChB,SAAiB,EACjB,cAAiC;QAEjC,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE;YAClD,SAAS;YACT,cAAc;SACf,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,QAAQ,CACN,GAAgB,EAChB,SAAiB,EACjB,WAAmB,EACnB,QAAiB;QAEjB,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE;YACnD,SAAS;YACT,WAAW;YACX,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,SAAS,CACP,GAAgB,EAChB,cAAiC,EACjC,SAAuD,EAAE;QAEzD,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE;YACpD,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,cAAc;SACf,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Public TypeScript surface for the memberships client. */
|
|
2
|
+
import type { PaginationOptions, PaginationResult } from "convex/server";
|
|
3
|
+
/**
|
|
4
|
+
* What a tuple's member points at — an opaque, host-classified string
|
|
5
|
+
* (e.g. `"user"`, `"group"`, `"resource"`, or any host-defined kind).
|
|
6
|
+
*/
|
|
7
|
+
export type MemberKind = string;
|
|
8
|
+
/** A member of a resource, as returned by {@link Memberships.listMembers}. */
|
|
9
|
+
export interface MemberEntry {
|
|
10
|
+
memberRef: string;
|
|
11
|
+
memberKind: MemberKind;
|
|
12
|
+
relation: string;
|
|
13
|
+
}
|
|
14
|
+
/** A resource a member relates to, as returned by {@link Memberships.members}. */
|
|
15
|
+
export interface ResourceEntry {
|
|
16
|
+
resourceRef: string;
|
|
17
|
+
relation: string;
|
|
18
|
+
}
|
|
19
|
+
/** A full membership edge, as returned by {@link Memberships.documents}. */
|
|
20
|
+
export interface MembershipDoc {
|
|
21
|
+
memberRef: string;
|
|
22
|
+
memberKind: MemberKind;
|
|
23
|
+
resourceRef: string;
|
|
24
|
+
relation: string;
|
|
25
|
+
/** Opaque host-stamped lifecycle marker, if any. */
|
|
26
|
+
status?: string;
|
|
27
|
+
/** Epoch milliseconds the edge was first inserted. */
|
|
28
|
+
createdAt: number;
|
|
29
|
+
}
|
|
30
|
+
/** Stable code-tag explaining why a {@link Memberships.setRelation} was rejected. */
|
|
31
|
+
export type SetRelationReason = "NOT_FOUND" | "EXISTS";
|
|
32
|
+
/** Result of {@link Memberships.setRelation} — may be rejected. */
|
|
33
|
+
export interface SetRelationResult {
|
|
34
|
+
ok: boolean;
|
|
35
|
+
/** Stable code-tag when `ok` is false. */
|
|
36
|
+
reason?: SetRelationReason;
|
|
37
|
+
}
|
|
38
|
+
/** Result of {@link Memberships.remove} — `removed` is true if an edge was deleted. */
|
|
39
|
+
export interface RemoveResult {
|
|
40
|
+
removed: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A page of results, mirroring Convex's `PaginationResult`. `continueCursor`
|
|
44
|
+
* feeds the next call's `paginationOpts.cursor`; `isDone` is true on the last page.
|
|
45
|
+
*/
|
|
46
|
+
export type Page<T> = Pick<PaginationResult<T>, "page" | "isDone" | "continueCursor">;
|
|
47
|
+
/** Pagination options, as accepted by the paginated client methods. */
|
|
48
|
+
export type { PaginationOptions };
|
|
49
|
+
/** Construction options for the {@link Memberships} client. */
|
|
50
|
+
export interface MembershipsOptions {
|
|
51
|
+
/** Relation applied when a call omits `relation`. Default `"member"`. */
|
|
52
|
+
defaultRelation?: string;
|
|
53
|
+
/** Member kind applied when a call omits `memberKind`. Default `"user"`. */
|
|
54
|
+
defaultMemberKind?: MemberKind;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAE5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEzE;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC,8EAA8E;AAC9E,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,kFAAkF;AAClF,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,4EAA4E;AAC5E,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qFAAqF;AACrF,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,QAAQ,CAAC;AAEvD,mEAAmE;AACnE,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,OAAO,CAAC;IACZ,0CAA0C;IAC1C,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC5B;AAED,uFAAuF;AACvF,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,IAAI,CACxB,gBAAgB,CAAC,CAAC,CAAC,EACnB,MAAM,GAAG,QAAQ,GAAG,gBAAgB,CACrC,CAAC;AAEF,uEAAuE;AACvE,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAElC,+DAA+D;AAC/D,MAAM,WAAW,kBAAkB;IACjC,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4EAA4E;IAC5E,iBAAiB,CAAC,EAAE,UAAU,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,4DAA4D"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated `api` utility.
|
|
3
|
+
*
|
|
4
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
5
|
+
*
|
|
6
|
+
* To regenerate, run `npx convex dev`.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type * as mutations from "../mutations.js";
|
|
10
|
+
import type * as queries from "../queries.js";
|
|
11
|
+
import type * as validators from "../validators.js";
|
|
12
|
+
import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
|
|
13
|
+
declare const fullApi: ApiFromModules<{
|
|
14
|
+
mutations: typeof mutations;
|
|
15
|
+
queries: typeof queries;
|
|
16
|
+
validators: typeof validators;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
20
|
+
*
|
|
21
|
+
* Usage:
|
|
22
|
+
* ```js
|
|
23
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
|
|
27
|
+
/**
|
|
28
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
29
|
+
*
|
|
30
|
+
* Usage:
|
|
31
|
+
* ```js
|
|
32
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
|
|
36
|
+
export declare const components: {};
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,KAAK,OAAO,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAGvB,QAAA,MAAM,OAAO,EAAE,cAAc,CAAC;IAC5B,SAAS,EAAE,OAAO,SAAS,CAAC;IAC5B,OAAO,EAAE,OAAO,OAAO,CAAC;IACxB,UAAU,EAAE,OAAO,UAAU,CAAC;CAC/B,CAAiB,CAAC;AAEnB;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,EAAE,SAAS,CACzB,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,CACjB,CAAC;AAElB;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,CAC9B,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,CACnB,CAAC;AAElB,eAAO,MAAM,UAAU,EAAqC,EAAE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
import { anyApi, componentsGeneric } from "convex/server";
|
|
11
|
+
const fullApi = anyApi;
|
|
12
|
+
/**
|
|
13
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```js
|
|
17
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const api = anyApi;
|
|
21
|
+
/**
|
|
22
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
23
|
+
*
|
|
24
|
+
* Usage:
|
|
25
|
+
* ```js
|
|
26
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const internal = anyApi;
|
|
30
|
+
export const components = componentsGeneric();
|
|
31
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAWH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,OAAO,GAIR,MAAa,CAAC;AAEnB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,GAAG,GAGZ,MAAa,CAAC;AAElB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAGjB,MAAa,CAAC;AAElB,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,EAAmB,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated `ComponentApi` utility.
|
|
3
|
+
*
|
|
4
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
5
|
+
*
|
|
6
|
+
* To regenerate, run `npx convex dev`.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { FunctionReference } from "convex/server";
|
|
10
|
+
/**
|
|
11
|
+
* A utility for referencing a Convex component's exposed API.
|
|
12
|
+
*
|
|
13
|
+
* Useful when expecting a parameter like `components.myComponent`.
|
|
14
|
+
* Usage:
|
|
15
|
+
* ```ts
|
|
16
|
+
* async function myFunction(ctx: QueryCtx, component: ComponentApi) {
|
|
17
|
+
* return ctx.runQuery(component.someFile.someQuery, { ...args });
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type ComponentApi<Name extends string | undefined = string | undefined> = {
|
|
22
|
+
mutations: {
|
|
23
|
+
add: FunctionReference<"mutation", "internal", {
|
|
24
|
+
memberKind: string;
|
|
25
|
+
memberRef: string;
|
|
26
|
+
relation: string;
|
|
27
|
+
resourceRef: string;
|
|
28
|
+
status?: string;
|
|
29
|
+
}, string, Name>;
|
|
30
|
+
remove: FunctionReference<"mutation", "internal", {
|
|
31
|
+
memberRef: string;
|
|
32
|
+
relation: string;
|
|
33
|
+
resourceRef: string;
|
|
34
|
+
}, {
|
|
35
|
+
removed: boolean;
|
|
36
|
+
}, Name>;
|
|
37
|
+
setRelation: FunctionReference<"mutation", "internal", {
|
|
38
|
+
fromRelation: string;
|
|
39
|
+
memberRef: string;
|
|
40
|
+
resourceRef: string;
|
|
41
|
+
toRelation: string;
|
|
42
|
+
}, {
|
|
43
|
+
ok: boolean;
|
|
44
|
+
reason?: "NOT_FOUND" | "EXISTS";
|
|
45
|
+
}, Name>;
|
|
46
|
+
};
|
|
47
|
+
queries: {
|
|
48
|
+
documents: FunctionReference<"query", "internal", {
|
|
49
|
+
memberRef?: string;
|
|
50
|
+
paginationOpts: {
|
|
51
|
+
cursor: string | null;
|
|
52
|
+
endCursor?: string | null;
|
|
53
|
+
id?: number;
|
|
54
|
+
maximumBytesRead?: number;
|
|
55
|
+
maximumRowsRead?: number;
|
|
56
|
+
numItems: number;
|
|
57
|
+
};
|
|
58
|
+
resourceRef?: string;
|
|
59
|
+
}, {
|
|
60
|
+
continueCursor: string;
|
|
61
|
+
isDone: boolean;
|
|
62
|
+
page: Array<{
|
|
63
|
+
createdAt: number;
|
|
64
|
+
memberKind: string;
|
|
65
|
+
memberRef: string;
|
|
66
|
+
relation: string;
|
|
67
|
+
resourceRef: string;
|
|
68
|
+
status?: string;
|
|
69
|
+
}>;
|
|
70
|
+
}, Name>;
|
|
71
|
+
isMember: FunctionReference<"query", "internal", {
|
|
72
|
+
memberRef: string;
|
|
73
|
+
relation?: string;
|
|
74
|
+
resourceRef: string;
|
|
75
|
+
}, boolean, Name>;
|
|
76
|
+
listMembers: FunctionReference<"query", "internal", {
|
|
77
|
+
paginationOpts: {
|
|
78
|
+
cursor: string | null;
|
|
79
|
+
endCursor?: string | null;
|
|
80
|
+
id?: number;
|
|
81
|
+
maximumBytesRead?: number;
|
|
82
|
+
maximumRowsRead?: number;
|
|
83
|
+
numItems: number;
|
|
84
|
+
};
|
|
85
|
+
relation?: string;
|
|
86
|
+
resourceRef: string;
|
|
87
|
+
}, {
|
|
88
|
+
continueCursor: string;
|
|
89
|
+
isDone: boolean;
|
|
90
|
+
page: Array<{
|
|
91
|
+
memberKind: string;
|
|
92
|
+
memberRef: string;
|
|
93
|
+
relation: string;
|
|
94
|
+
}>;
|
|
95
|
+
}, Name>;
|
|
96
|
+
members: FunctionReference<"query", "internal", {
|
|
97
|
+
memberRef: string;
|
|
98
|
+
paginationOpts: {
|
|
99
|
+
cursor: string | null;
|
|
100
|
+
endCursor?: string | null;
|
|
101
|
+
id?: number;
|
|
102
|
+
maximumBytesRead?: number;
|
|
103
|
+
maximumRowsRead?: number;
|
|
104
|
+
numItems: number;
|
|
105
|
+
};
|
|
106
|
+
}, {
|
|
107
|
+
continueCursor: string;
|
|
108
|
+
isDone: boolean;
|
|
109
|
+
page: Array<{
|
|
110
|
+
relation: string;
|
|
111
|
+
resourceRef: string;
|
|
112
|
+
}>;
|
|
113
|
+
}, Name>;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=component.d.ts.map
|