@vllnt/convex-comments 0.1.0-canary.3e5064a
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 +130 -0
- package/dist/client/index.d.ts +146 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +133 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +51 -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 +40 -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 +98 -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/crons.d.ts +16 -0
- package/dist/component/crons.d.ts.map +1 -0
- package/dist/component/crons.js +19 -0
- package/dist/component/crons.js.map +1 -0
- package/dist/component/mutations.d.ts +81 -0
- package/dist/component/mutations.d.ts.map +1 -0
- package/dist/component/mutations.js +223 -0
- package/dist/component/mutations.js.map +1 -0
- package/dist/component/queries.d.ts +61 -0
- package/dist/component/queries.d.ts.map +1 -0
- package/dist/component/queries.js +82 -0
- package/dist/component/queries.js.map +1 -0
- package/dist/component/schema.d.ts +42 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +34 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/validators.d.ts +46 -0
- package/dist/component/validators.d.ts.map +1 -0
- package/dist/component/validators.js +37 -0
- package/dist/component/validators.js.map +1 -0
- package/dist/shared.d.ts +25 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +26 -0
- package/dist/shared.js.map +1 -0
- package/package.json +98 -0
- package/src/client/index.ts +299 -0
- package/src/client/types.ts +55 -0
- package/src/component/_generated/api.ts +56 -0
- package/src/component/_generated/component.ts +129 -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/crons.ts +23 -0
- package/src/component/mutations.ts +234 -0
- package/src/component/queries.ts +96 -0
- package/src/component/schema.ts +34 -0
- package/src/component/validators.ts +44 -0
- package/src/shared.ts +33 -0
- package/src/test.ts +15 -0
package/package.json
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vllnt/convex-comments",
|
|
3
|
+
"version": "0.1.0-canary.3e5064a",
|
|
4
|
+
"description": "Threaded comments / annotations on any resource — post, reply, edit, resolve, and soft-delete 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
|
+
"./test": "./src/test.ts",
|
|
19
|
+
"./_generated/component.js": {
|
|
20
|
+
"types": "./dist/component/_generated/component.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./_generated/component": {
|
|
23
|
+
"types": "./dist/component/_generated/component.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./convex.config": {
|
|
26
|
+
"types": "./dist/component/convex.config.d.ts",
|
|
27
|
+
"default": "./dist/component/convex.config.js"
|
|
28
|
+
},
|
|
29
|
+
"./convex.config.js": {
|
|
30
|
+
"types": "./dist/component/convex.config.d.ts",
|
|
31
|
+
"default": "./dist/component/convex.config.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"types": "./dist/client/index.d.ts",
|
|
35
|
+
"module": "./dist/client/index.js",
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc --project ./tsconfig.build.json",
|
|
38
|
+
"build:codegen": "pnpm convex codegen --component-dir ./src/component && pnpm build",
|
|
39
|
+
"build:clean": "rm -rf dist *.tsbuildinfo && pnpm build:codegen",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"typecheck:ci": "tsc --noEmit --project tsconfig.ci.json",
|
|
42
|
+
"lint": "eslint .",
|
|
43
|
+
"test": "vitest run --passWithNoTests",
|
|
44
|
+
"test:watch": "vitest --typecheck --clearScreen false",
|
|
45
|
+
"test:coverage": "vitest run --coverage --coverage.reporter=text",
|
|
46
|
+
"generate:llms": "node scripts/generate-llms.mjs",
|
|
47
|
+
"preversion": "pnpm install --frozen-lockfile && pnpm build && pnpm test:coverage && pnpm typecheck && pnpm generate:llms",
|
|
48
|
+
"prepublishOnly": "npm whoami || npm login",
|
|
49
|
+
"alpha": "npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
|
|
50
|
+
"release": "npm version patch && npm publish && git push --follow-tags"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"convex": "^1.41.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@edge-runtime/vm": "^5.0.0",
|
|
58
|
+
"@vitest/coverage-v8": "^4.1.8",
|
|
59
|
+
"@vllnt/eslint-config": "^1.0.0",
|
|
60
|
+
"@vllnt/typescript": "^1.0.0",
|
|
61
|
+
"convex": "^1.41.0",
|
|
62
|
+
"convex-test": "^0.0.53",
|
|
63
|
+
"eslint": "^9.0.0",
|
|
64
|
+
"prettier": "^3.4.0",
|
|
65
|
+
"typescript": "^5.7.0",
|
|
66
|
+
"vitest": "^4.1.8"
|
|
67
|
+
},
|
|
68
|
+
"homepage": "https://github.com/vllnt/convex-comments#readme",
|
|
69
|
+
"bugs": {
|
|
70
|
+
"url": "https://github.com/vllnt/convex-comments/issues"
|
|
71
|
+
},
|
|
72
|
+
"author": {
|
|
73
|
+
"name": "bntvllnt",
|
|
74
|
+
"url": "https://bntvllnt.com"
|
|
75
|
+
},
|
|
76
|
+
"funding": {
|
|
77
|
+
"type": "github",
|
|
78
|
+
"url": "https://github.com/sponsors/bntvllnt"
|
|
79
|
+
},
|
|
80
|
+
"repository": {
|
|
81
|
+
"type": "git",
|
|
82
|
+
"url": "https://github.com/vllnt/convex-comments"
|
|
83
|
+
},
|
|
84
|
+
"engines": {
|
|
85
|
+
"node": ">=18"
|
|
86
|
+
},
|
|
87
|
+
"publishConfig": {
|
|
88
|
+
"access": "public"
|
|
89
|
+
},
|
|
90
|
+
"sideEffects": false,
|
|
91
|
+
"keywords": [
|
|
92
|
+
"convex",
|
|
93
|
+
"convex-component",
|
|
94
|
+
"comments",
|
|
95
|
+
"threads",
|
|
96
|
+
"annotations"
|
|
97
|
+
]
|
|
98
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FunctionArgs,
|
|
3
|
+
FunctionReference,
|
|
4
|
+
FunctionReturnType,
|
|
5
|
+
PaginationOptions,
|
|
6
|
+
PaginationResult,
|
|
7
|
+
} from "convex/server";
|
|
8
|
+
import type {
|
|
9
|
+
CommentStatus,
|
|
10
|
+
CommentView,
|
|
11
|
+
CommentsOptions,
|
|
12
|
+
ListOptions,
|
|
13
|
+
Parser,
|
|
14
|
+
} from "./types.js";
|
|
15
|
+
import { DEFAULT_PRUNE_BATCH } from "../shared.js";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The component's raw comment view, before the client narrows the opaque host
|
|
19
|
+
* body. `body` is `unknown` here; the {@link Comments} client runs the host
|
|
20
|
+
* validator over it at its typed boundary.
|
|
21
|
+
*/
|
|
22
|
+
type RawView = {
|
|
23
|
+
commentId: string;
|
|
24
|
+
resourceRef: string;
|
|
25
|
+
authorRef: string;
|
|
26
|
+
parentId?: string;
|
|
27
|
+
body?: unknown;
|
|
28
|
+
status: CommentStatus;
|
|
29
|
+
editedAt?: number;
|
|
30
|
+
createdAt: number;
|
|
31
|
+
updatedAt: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The comments component's function references, as exposed on the host via
|
|
36
|
+
* `components.comments`. The host's stored `body` is opaque here (`unknown`); the
|
|
37
|
+
* {@link Comments} client narrows it at its own typed boundary.
|
|
38
|
+
*/
|
|
39
|
+
export interface CommentsComponent {
|
|
40
|
+
mutations: {
|
|
41
|
+
post: FunctionReference<
|
|
42
|
+
"mutation",
|
|
43
|
+
"internal",
|
|
44
|
+
{
|
|
45
|
+
resourceRef: string;
|
|
46
|
+
authorRef: string;
|
|
47
|
+
body: unknown;
|
|
48
|
+
parentId?: string;
|
|
49
|
+
},
|
|
50
|
+
{ commentId: string }
|
|
51
|
+
>;
|
|
52
|
+
edit: FunctionReference<
|
|
53
|
+
"mutation",
|
|
54
|
+
"internal",
|
|
55
|
+
{ commentId: string; authorRef: string; body: unknown },
|
|
56
|
+
null
|
|
57
|
+
>;
|
|
58
|
+
remove: FunctionReference<
|
|
59
|
+
"mutation",
|
|
60
|
+
"internal",
|
|
61
|
+
{ commentId: string; authorRef: string },
|
|
62
|
+
null
|
|
63
|
+
>;
|
|
64
|
+
resolve: FunctionReference<
|
|
65
|
+
"mutation",
|
|
66
|
+
"internal",
|
|
67
|
+
{ commentId: string; authorRef: string; resolved: boolean },
|
|
68
|
+
null
|
|
69
|
+
>;
|
|
70
|
+
prune: FunctionReference<
|
|
71
|
+
"mutation",
|
|
72
|
+
"internal",
|
|
73
|
+
{ before?: number; batch: number },
|
|
74
|
+
number
|
|
75
|
+
>;
|
|
76
|
+
};
|
|
77
|
+
queries: {
|
|
78
|
+
get: FunctionReference<
|
|
79
|
+
"query",
|
|
80
|
+
"internal",
|
|
81
|
+
{ commentId: string },
|
|
82
|
+
RawView | null
|
|
83
|
+
>;
|
|
84
|
+
list: FunctionReference<
|
|
85
|
+
"query",
|
|
86
|
+
"internal",
|
|
87
|
+
{
|
|
88
|
+
resourceRef: string;
|
|
89
|
+
parentId?: string;
|
|
90
|
+
includeDeleted?: boolean;
|
|
91
|
+
paginationOpts: PaginationOptions;
|
|
92
|
+
},
|
|
93
|
+
PaginationResult<RawView>
|
|
94
|
+
>;
|
|
95
|
+
count: FunctionReference<
|
|
96
|
+
"query",
|
|
97
|
+
"internal",
|
|
98
|
+
{ resourceRef: string },
|
|
99
|
+
number
|
|
100
|
+
>;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface RunQueryCtx {
|
|
105
|
+
runQuery<Q extends FunctionReference<"query", "internal">>(
|
|
106
|
+
reference: Q,
|
|
107
|
+
args: FunctionArgs<Q>,
|
|
108
|
+
): Promise<FunctionReturnType<Q>>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
interface RunMutationCtx {
|
|
112
|
+
runMutation<M extends FunctionReference<"mutation", "internal">>(
|
|
113
|
+
reference: M,
|
|
114
|
+
args: FunctionArgs<M>,
|
|
115
|
+
): Promise<FunctionReturnType<M>>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Consumer-facing client for threaded comments / annotations on any resource. A
|
|
120
|
+
* host mutation calls `post(resourceRef, authorRef, body, parentId?)` to attach a
|
|
121
|
+
* comment to an opaque resource; `edit` / `remove` / `resolve` mutate it
|
|
122
|
+
* (author-gated by the component); `list` pages a resource's thread and `count`
|
|
123
|
+
* tallies it. The host owns meaning and auth — it resolves identity, decides
|
|
124
|
+
* access, and passes opaque `resourceRef` / `authorRef`. The body is opaque host
|
|
125
|
+
* data the component stores without inspecting; pass `bodyValidator` to narrow it
|
|
126
|
+
* to `TBody` at the boundary (plain text vs rich blocks — the host decides).
|
|
127
|
+
*
|
|
128
|
+
* @typeParam TBody - The host's comment body type (defaults to `unknown`).
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* const comments = new Comments(components.comments, {
|
|
133
|
+
* bodyValidator: v.string().parse,
|
|
134
|
+
* });
|
|
135
|
+
* const { commentId } = await comments.post(ctx, "post:42", "user:7", "hello");
|
|
136
|
+
* const reply = await comments.post(ctx, "post:42", "user:9", "hi", commentId);
|
|
137
|
+
* const thread = await comments.list(ctx, "post:42", { cursor: null, numItems: 50 });
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export class Comments<TBody = unknown> {
|
|
141
|
+
private readonly bodyValidator: Parser<TBody> | undefined;
|
|
142
|
+
|
|
143
|
+
constructor(
|
|
144
|
+
private readonly component: CommentsComponent,
|
|
145
|
+
options: CommentsOptions<TBody> = {},
|
|
146
|
+
) {
|
|
147
|
+
this.bodyValidator = options.bodyValidator;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Narrow an opaque value through the host parser; pass `undefined` and an unset parser through. */
|
|
151
|
+
private parse(value: unknown): TBody | undefined {
|
|
152
|
+
if (value === undefined) {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
if (this.bodyValidator === undefined) {
|
|
156
|
+
return value as TBody;
|
|
157
|
+
}
|
|
158
|
+
return this.bodyValidator(value);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Project a raw component view into the typed, validated client view. */
|
|
162
|
+
private view(raw: RawView): CommentView<TBody> {
|
|
163
|
+
return {
|
|
164
|
+
commentId: raw.commentId,
|
|
165
|
+
resourceRef: raw.resourceRef,
|
|
166
|
+
authorRef: raw.authorRef,
|
|
167
|
+
parentId: raw.parentId,
|
|
168
|
+
body: this.parse(raw.body),
|
|
169
|
+
status: raw.status,
|
|
170
|
+
editedAt: raw.editedAt,
|
|
171
|
+
createdAt: raw.createdAt,
|
|
172
|
+
updatedAt: raw.updatedAt,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Post a comment on `resourceRef` authored by `authorRef` and return its id.
|
|
178
|
+
* `body` is opaque host data validated against `bodyValidator` before storage.
|
|
179
|
+
* `parentId`, when given, threads the comment as a reply. The comment starts
|
|
180
|
+
* `open`.
|
|
181
|
+
*/
|
|
182
|
+
async post(
|
|
183
|
+
ctx: RunMutationCtx,
|
|
184
|
+
resourceRef: string,
|
|
185
|
+
authorRef: string,
|
|
186
|
+
body: TBody,
|
|
187
|
+
parentId?: string,
|
|
188
|
+
): Promise<{ commentId: string }> {
|
|
189
|
+
return ctx.runMutation(this.component.mutations.post, {
|
|
190
|
+
resourceRef,
|
|
191
|
+
authorRef,
|
|
192
|
+
body: this.parse(body),
|
|
193
|
+
parentId,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Edit a comment's body. The component rejects a non-author caller and a
|
|
199
|
+
* soft-deleted comment. `body` is validated against `bodyValidator` before
|
|
200
|
+
* storage.
|
|
201
|
+
*/
|
|
202
|
+
edit(
|
|
203
|
+
ctx: RunMutationCtx,
|
|
204
|
+
commentId: string,
|
|
205
|
+
authorRef: string,
|
|
206
|
+
body: TBody,
|
|
207
|
+
): Promise<null> {
|
|
208
|
+
return ctx.runMutation(this.component.mutations.edit, {
|
|
209
|
+
commentId,
|
|
210
|
+
authorRef,
|
|
211
|
+
body: this.parse(body),
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Soft-delete a comment (author-gated by the component); replies are preserved. */
|
|
216
|
+
remove(
|
|
217
|
+
ctx: RunMutationCtx,
|
|
218
|
+
commentId: string,
|
|
219
|
+
authorRef: string,
|
|
220
|
+
): Promise<null> {
|
|
221
|
+
return ctx.runMutation(this.component.mutations.remove, {
|
|
222
|
+
commentId,
|
|
223
|
+
authorRef,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** Toggle a comment's resolved state (author-gated); `resolved` defaults to `true`. */
|
|
228
|
+
resolve(
|
|
229
|
+
ctx: RunMutationCtx,
|
|
230
|
+
commentId: string,
|
|
231
|
+
authorRef: string,
|
|
232
|
+
resolved = true,
|
|
233
|
+
): Promise<null> {
|
|
234
|
+
return ctx.runMutation(this.component.mutations.resolve, {
|
|
235
|
+
commentId,
|
|
236
|
+
authorRef,
|
|
237
|
+
resolved,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** The current view of `commentId`, or `null` if no such comment is held. */
|
|
242
|
+
async get(
|
|
243
|
+
ctx: RunQueryCtx,
|
|
244
|
+
commentId: string,
|
|
245
|
+
): Promise<CommentView<TBody> | null> {
|
|
246
|
+
const raw = await ctx.runQuery(this.component.queries.get, { commentId });
|
|
247
|
+
return raw === null ? null : this.view(raw);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Page a resource's comments oldest first. By default pages the resource's
|
|
252
|
+
* top level (excluding soft-deleted); pass `opts.parentId` to page one
|
|
253
|
+
* comment's replies, or `opts.includeDeleted` to include removed comments.
|
|
254
|
+
* Returns the standard Convex pagination envelope with each row narrowed.
|
|
255
|
+
*/
|
|
256
|
+
async list(
|
|
257
|
+
ctx: RunQueryCtx,
|
|
258
|
+
resourceRef: string,
|
|
259
|
+
paginationOpts: PaginationOptions,
|
|
260
|
+
opts: ListOptions = {},
|
|
261
|
+
): Promise<PaginationResult<CommentView<TBody>>> {
|
|
262
|
+
const result = await ctx.runQuery(this.component.queries.list, {
|
|
263
|
+
resourceRef,
|
|
264
|
+
parentId: opts.parentId,
|
|
265
|
+
includeDeleted: opts.includeDeleted,
|
|
266
|
+
paginationOpts,
|
|
267
|
+
});
|
|
268
|
+
return { ...result, page: result.page.map((raw) => this.view(raw)) };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Count the visible (non-deleted) comments on `resourceRef`. */
|
|
272
|
+
count(ctx: RunQueryCtx, resourceRef: string): Promise<number> {
|
|
273
|
+
return ctx.runQuery(this.component.queries.count, { resourceRef });
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Delete soft-deleted comments whose `updatedAt < before` in bounded batches,
|
|
278
|
+
* oldest first. `before` defaults to the server clock; `batch` caps each pass
|
|
279
|
+
* and the sweep self-reschedules until the tail is clean. Returns the count
|
|
280
|
+
* removed in the first pass. The built-in daily cron drives this automatically.
|
|
281
|
+
*/
|
|
282
|
+
prune(
|
|
283
|
+
ctx: RunMutationCtx,
|
|
284
|
+
opts: { before?: number; batch?: number } = {},
|
|
285
|
+
): Promise<number> {
|
|
286
|
+
return ctx.runMutation(this.component.mutations.prune, {
|
|
287
|
+
before: opts.before,
|
|
288
|
+
batch: opts.batch ?? DEFAULT_PRUNE_BATCH,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export type {
|
|
294
|
+
CommentStatus,
|
|
295
|
+
CommentView,
|
|
296
|
+
CommentsOptions,
|
|
297
|
+
ListOptions,
|
|
298
|
+
Parser,
|
|
299
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Public TypeScript surface for the comments client. */
|
|
2
|
+
|
|
3
|
+
/** The three lifecycle statuses a comment moves through. */
|
|
4
|
+
export type CommentStatus = "open" | "resolved" | "deleted";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Validates and narrows an opaque stored comment `body` to a host type `T` at the
|
|
8
|
+
* client boundary. Receives the raw value the component returned (`unknown`) and
|
|
9
|
+
* MUST return a typed `T` or throw. A `convex/values` validator's `.parse` (or a
|
|
10
|
+
* Zod `.parse`) fits directly; omit it to keep the value unvalidated.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam T - The host's stored comment body type.
|
|
13
|
+
*/
|
|
14
|
+
export type Parser<T> = (value: unknown) => T;
|
|
15
|
+
|
|
16
|
+
/** The public view returned by {@link Comments.get} / {@link Comments.list}. */
|
|
17
|
+
export interface CommentView<TBody = unknown> {
|
|
18
|
+
/** The component-assigned opaque id naming this comment. */
|
|
19
|
+
commentId: string;
|
|
20
|
+
/** The host-supplied ref of the resource this comment is attached to. */
|
|
21
|
+
resourceRef: string;
|
|
22
|
+
/** The host-supplied ref of the comment's author. */
|
|
23
|
+
authorRef: string;
|
|
24
|
+
/** The opaque id of the comment this one replies to, when threaded. */
|
|
25
|
+
parentId?: string;
|
|
26
|
+
/** The opaque host body (narrowed if a `bodyValidator` is set); absent once deleted. */
|
|
27
|
+
body?: TBody;
|
|
28
|
+
/** The current lifecycle status. */
|
|
29
|
+
status: CommentStatus;
|
|
30
|
+
/** Absolute ms timestamp of the last body edit, if any. */
|
|
31
|
+
editedAt?: number;
|
|
32
|
+
/** Absolute ms timestamp the comment was posted. */
|
|
33
|
+
createdAt: number;
|
|
34
|
+
/** Absolute ms timestamp of the last write (edit, resolve, or delete). */
|
|
35
|
+
updatedAt: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Per-call options for {@link Comments.list}. */
|
|
39
|
+
export interface ListOptions {
|
|
40
|
+
/** Page one parent comment's direct replies instead of the resource's top level. */
|
|
41
|
+
parentId?: string;
|
|
42
|
+
/** Include soft-deleted comments in the page (excluded by default). */
|
|
43
|
+
includeDeleted?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Construction options for the {@link Comments} client. */
|
|
47
|
+
export interface CommentsOptions<TBody> {
|
|
48
|
+
/**
|
|
49
|
+
* Validates/narrows a stored comment `body` to `TBody` at the boundary — applied
|
|
50
|
+
* to the `body` passed into `post` / `edit` (before storage) and the `body`
|
|
51
|
+
* returned by `get` / `list`. Throws on a mismatch. Omit to leave bodies
|
|
52
|
+
* unvalidated (plain text needs no validator; rich-block hosts pass their schema).
|
|
53
|
+
*/
|
|
54
|
+
bodyValidator?: Parser<TBody>;
|
|
55
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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 crons from "../crons.js";
|
|
12
|
+
import type * as mutations from "../mutations.js";
|
|
13
|
+
import type * as queries from "../queries.js";
|
|
14
|
+
import type * as validators from "../validators.js";
|
|
15
|
+
|
|
16
|
+
import type {
|
|
17
|
+
ApiFromModules,
|
|
18
|
+
FilterApi,
|
|
19
|
+
FunctionReference,
|
|
20
|
+
} from "convex/server";
|
|
21
|
+
import { anyApi, componentsGeneric } from "convex/server";
|
|
22
|
+
|
|
23
|
+
const fullApi: ApiFromModules<{
|
|
24
|
+
crons: typeof crons;
|
|
25
|
+
mutations: typeof mutations;
|
|
26
|
+
queries: typeof queries;
|
|
27
|
+
validators: typeof validators;
|
|
28
|
+
}> = anyApi as any;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
32
|
+
*
|
|
33
|
+
* Usage:
|
|
34
|
+
* ```js
|
|
35
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const api: FilterApi<
|
|
39
|
+
typeof fullApi,
|
|
40
|
+
FunctionReference<any, "public">
|
|
41
|
+
> = anyApi as any;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
45
|
+
*
|
|
46
|
+
* Usage:
|
|
47
|
+
* ```js
|
|
48
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export const internal: FilterApi<
|
|
52
|
+
typeof fullApi,
|
|
53
|
+
FunctionReference<any, "internal">
|
|
54
|
+
> = anyApi as any;
|
|
55
|
+
|
|
56
|
+
export const components = componentsGeneric() as unknown as {};
|
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
post: FunctionReference<
|
|
28
|
+
"mutation",
|
|
29
|
+
"internal",
|
|
30
|
+
{
|
|
31
|
+
authorRef: string;
|
|
32
|
+
body: any;
|
|
33
|
+
parentId?: string;
|
|
34
|
+
resourceRef: string;
|
|
35
|
+
},
|
|
36
|
+
{ commentId: string },
|
|
37
|
+
Name
|
|
38
|
+
>;
|
|
39
|
+
edit: FunctionReference<
|
|
40
|
+
"mutation",
|
|
41
|
+
"internal",
|
|
42
|
+
{ authorRef: string; body: any; commentId: string },
|
|
43
|
+
null,
|
|
44
|
+
Name
|
|
45
|
+
>;
|
|
46
|
+
remove: FunctionReference<
|
|
47
|
+
"mutation",
|
|
48
|
+
"internal",
|
|
49
|
+
{ authorRef: string; commentId: string },
|
|
50
|
+
null,
|
|
51
|
+
Name
|
|
52
|
+
>;
|
|
53
|
+
resolve: FunctionReference<
|
|
54
|
+
"mutation",
|
|
55
|
+
"internal",
|
|
56
|
+
{ authorRef: string; commentId: string; resolved: boolean },
|
|
57
|
+
null,
|
|
58
|
+
Name
|
|
59
|
+
>;
|
|
60
|
+
prune: FunctionReference<
|
|
61
|
+
"mutation",
|
|
62
|
+
"internal",
|
|
63
|
+
{ batch: number; before?: number },
|
|
64
|
+
number,
|
|
65
|
+
Name
|
|
66
|
+
>;
|
|
67
|
+
};
|
|
68
|
+
queries: {
|
|
69
|
+
get: FunctionReference<
|
|
70
|
+
"query",
|
|
71
|
+
"internal",
|
|
72
|
+
{ commentId: string },
|
|
73
|
+
null | {
|
|
74
|
+
authorRef: string;
|
|
75
|
+
body?: any;
|
|
76
|
+
commentId: string;
|
|
77
|
+
createdAt: number;
|
|
78
|
+
editedAt?: number;
|
|
79
|
+
parentId?: string;
|
|
80
|
+
resourceRef: string;
|
|
81
|
+
status: "open" | "resolved" | "deleted";
|
|
82
|
+
updatedAt: number;
|
|
83
|
+
},
|
|
84
|
+
Name
|
|
85
|
+
>;
|
|
86
|
+
list: FunctionReference<
|
|
87
|
+
"query",
|
|
88
|
+
"internal",
|
|
89
|
+
{
|
|
90
|
+
includeDeleted?: boolean;
|
|
91
|
+
paginationOpts: {
|
|
92
|
+
cursor: string | null;
|
|
93
|
+
endCursor?: string | null;
|
|
94
|
+
id?: number;
|
|
95
|
+
maximumBytesRead?: number;
|
|
96
|
+
maximumRowsRead?: number;
|
|
97
|
+
numItems: number;
|
|
98
|
+
};
|
|
99
|
+
parentId?: string;
|
|
100
|
+
resourceRef: string;
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
continueCursor: string;
|
|
104
|
+
isDone: boolean;
|
|
105
|
+
page: Array<{
|
|
106
|
+
authorRef: string;
|
|
107
|
+
body?: any;
|
|
108
|
+
commentId: string;
|
|
109
|
+
createdAt: number;
|
|
110
|
+
editedAt?: number;
|
|
111
|
+
parentId?: string;
|
|
112
|
+
resourceRef: string;
|
|
113
|
+
status: "open" | "resolved" | "deleted";
|
|
114
|
+
updatedAt: number;
|
|
115
|
+
}>;
|
|
116
|
+
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
117
|
+
splitCursor?: string | null;
|
|
118
|
+
},
|
|
119
|
+
Name
|
|
120
|
+
>;
|
|
121
|
+
count: FunctionReference<
|
|
122
|
+
"query",
|
|
123
|
+
"internal",
|
|
124
|
+
{ resourceRef: string },
|
|
125
|
+
number,
|
|
126
|
+
Name
|
|
127
|
+
>;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated data model types.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
DataModelFromSchemaDefinition,
|
|
13
|
+
DocumentByName,
|
|
14
|
+
TableNamesInDataModel,
|
|
15
|
+
SystemTableNames,
|
|
16
|
+
} from "convex/server";
|
|
17
|
+
import type { GenericId } from "convex/values";
|
|
18
|
+
import schema from "../schema.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The names of all of your Convex tables.
|
|
22
|
+
*/
|
|
23
|
+
export type TableNames = TableNamesInDataModel<DataModel>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The type of a document stored in Convex.
|
|
27
|
+
*
|
|
28
|
+
* @typeParam TableName - A string literal type of the table name (like "users").
|
|
29
|
+
*/
|
|
30
|
+
export type Doc<TableName extends TableNames> = DocumentByName<
|
|
31
|
+
DataModel,
|
|
32
|
+
TableName
|
|
33
|
+
>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* An identifier for a document in Convex.
|
|
37
|
+
*
|
|
38
|
+
* Convex documents are uniquely identified by their `Id`, which is accessible
|
|
39
|
+
* on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
|
|
40
|
+
*
|
|
41
|
+
* Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.
|
|
42
|
+
*
|
|
43
|
+
* IDs are just strings at runtime, but this type can be used to distinguish them from other
|
|
44
|
+
* strings when type checking.
|
|
45
|
+
*
|
|
46
|
+
* @typeParam TableName - A string literal type of the table name (like "users").
|
|
47
|
+
*/
|
|
48
|
+
export type Id<TableName extends TableNames | SystemTableNames> =
|
|
49
|
+
GenericId<TableName>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A type describing your Convex data model.
|
|
53
|
+
*
|
|
54
|
+
* This type includes information about what tables you have, the type of
|
|
55
|
+
* documents stored in those tables, and the indexes defined on them.
|
|
56
|
+
*
|
|
57
|
+
* This type is used to parameterize methods like `queryGeneric` and
|
|
58
|
+
* `mutationGeneric` to make them type-safe.
|
|
59
|
+
*/
|
|
60
|
+
export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
|