vibesuite 1.3.3 → 2.0.2
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/README.md +75 -6
- package/assets/.agent/skills/avoid-feature-creep/SKILL.md +307 -0
- package/assets/.agent/skills/avoid-feature-creep/agents/openai.yaml +3 -0
- package/assets/.agent/skills/avoid-feature-creep/assets/large-logo.png +0 -0
- package/assets/.agent/skills/avoid-feature-creep/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex/SKILL.md +62 -0
- package/assets/.agent/skills/convex/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-agents/SKILL.md +516 -0
- package/assets/.agent/skills/convex-agents/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-agents/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-agents/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-best-practices/SKILL.md +369 -0
- package/assets/.agent/skills/convex-best-practices/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-best-practices/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-best-practices/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-component-authoring/SKILL.md +457 -0
- package/assets/.agent/skills/convex-component-authoring/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-component-authoring/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-component-authoring/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-cron-jobs/SKILL.md +604 -0
- package/assets/.agent/skills/convex-cron-jobs/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-cron-jobs/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-cron-jobs/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-file-storage/SKILL.md +467 -0
- package/assets/.agent/skills/convex-file-storage/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-file-storage/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-file-storage/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-functions/SKILL.md +458 -0
- package/assets/.agent/skills/convex-functions/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-functions/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-functions/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-http-actions/SKILL.md +733 -0
- package/assets/.agent/skills/convex-http-actions/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-http-actions/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-http-actions/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-migrations/SKILL.md +712 -0
- package/assets/.agent/skills/convex-migrations/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-migrations/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-migrations/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-realtime/SKILL.md +443 -0
- package/assets/.agent/skills/convex-realtime/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-realtime/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-realtime/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-schema-validator/SKILL.md +400 -0
- package/assets/.agent/skills/convex-schema-validator/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-schema-validator/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-schema-validator/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-security-audit/SKILL.md +539 -0
- package/assets/.agent/skills/convex-security-audit/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-security-audit/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-security-audit/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-security-check/SKILL.md +378 -0
- package/assets/.agent/skills/convex-security-check/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-security-check/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-security-check/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/github-ops/SKILL.md +4 -4
- package/assets/.agent/skills/google-trends/SKILL.md +7 -7
- package/assets/.agent/skills/optimize-agent-context/SKILL.md +97 -0
- package/assets/.agent/skills/youtube-pipeline/SKILL.md +10 -10
- package/assets/.agent/workflows/LEGACY/init_smart_ops.md +2 -2
- package/assets/.agent/workflows/agent_reset.md +4 -6
- package/assets/.agent/workflows/mode-orchestrator.md +17 -22
- package/assets/.agent/workflows/mode-visionary.md +3 -10
- package/assets/.agent/workflows/optimize-agent-context.md +54 -0
- package/assets/.agent/workflows/remotion-build.md +17 -17
- package/assets/.agent/workflows/stitch.md +4 -4
- package/assets/VibeCode-Agents/vibe-orchestrator.yaml +14 -33
- package/assets/VibeCode-Agents/vibe-visionary.yaml +3 -13
- package/package.json +1 -1
- package/src/cli.js +416 -20
- package/src/harness.js +281 -0
- package/src/store.js +239 -0
- package/assets/VibeCode-Agents/custom_modes.yaml +0 -979
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: convex-functions
|
|
3
|
+
displayName: Convex Functions
|
|
4
|
+
description: Writing queries, mutations, actions, and HTTP actions with proper argument validation, error handling, internal functions, and runtime considerations
|
|
5
|
+
version: 1.0.0
|
|
6
|
+
author: Convex
|
|
7
|
+
tags: [convex, functions, queries, mutations, actions, http]
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Convex Functions
|
|
11
|
+
|
|
12
|
+
Master Convex functions including queries, mutations, actions, and HTTP endpoints with proper validation, error handling, and runtime considerations.
|
|
13
|
+
|
|
14
|
+
## Code Quality
|
|
15
|
+
|
|
16
|
+
All examples in this skill comply with @convex-dev/eslint-plugin rules:
|
|
17
|
+
|
|
18
|
+
- Object syntax with `handler` property
|
|
19
|
+
- Argument validators on all functions
|
|
20
|
+
- Explicit table names in database operations
|
|
21
|
+
|
|
22
|
+
See the Code Quality section in [convex-best-practices](../convex-best-practices/SKILL.md) for linting setup.
|
|
23
|
+
|
|
24
|
+
## Documentation Sources
|
|
25
|
+
|
|
26
|
+
Before implementing, do not assume; fetch the latest documentation:
|
|
27
|
+
|
|
28
|
+
- Primary: https://docs.convex.dev/functions
|
|
29
|
+
- Query Functions: https://docs.convex.dev/functions/query-functions
|
|
30
|
+
- Mutation Functions: https://docs.convex.dev/functions/mutation-functions
|
|
31
|
+
- Actions: https://docs.convex.dev/functions/actions
|
|
32
|
+
- HTTP Actions: https://docs.convex.dev/functions/http-actions
|
|
33
|
+
- For broader context: https://docs.convex.dev/llms.txt
|
|
34
|
+
|
|
35
|
+
## Instructions
|
|
36
|
+
|
|
37
|
+
### Function Types Overview
|
|
38
|
+
|
|
39
|
+
| Type | Database Access | External APIs | Caching | Use Case |
|
|
40
|
+
| ----------- | ------------------------ | ------------- | ------------- | --------------------- |
|
|
41
|
+
| Query | Read-only | No | Yes, reactive | Fetching data |
|
|
42
|
+
| Mutation | Read/Write | No | No | Modifying data |
|
|
43
|
+
| Action | Via runQuery/runMutation | Yes | No | External integrations |
|
|
44
|
+
| HTTP Action | Via runQuery/runMutation | Yes | No | Webhooks, APIs |
|
|
45
|
+
|
|
46
|
+
### Queries
|
|
47
|
+
|
|
48
|
+
Queries are reactive, cached, and read-only:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { query } from "./_generated/server";
|
|
52
|
+
import { v } from "convex/values";
|
|
53
|
+
|
|
54
|
+
export const getUser = query({
|
|
55
|
+
args: { userId: v.id("users") },
|
|
56
|
+
returns: v.union(
|
|
57
|
+
v.object({
|
|
58
|
+
_id: v.id("users"),
|
|
59
|
+
_creationTime: v.number(),
|
|
60
|
+
name: v.string(),
|
|
61
|
+
email: v.string(),
|
|
62
|
+
}),
|
|
63
|
+
v.null(),
|
|
64
|
+
),
|
|
65
|
+
handler: async (ctx, args) => {
|
|
66
|
+
return await ctx.db.get("users", args.userId);
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Query with index
|
|
71
|
+
export const listUserTasks = query({
|
|
72
|
+
args: { userId: v.id("users") },
|
|
73
|
+
returns: v.array(
|
|
74
|
+
v.object({
|
|
75
|
+
_id: v.id("tasks"),
|
|
76
|
+
_creationTime: v.number(),
|
|
77
|
+
title: v.string(),
|
|
78
|
+
completed: v.boolean(),
|
|
79
|
+
}),
|
|
80
|
+
),
|
|
81
|
+
handler: async (ctx, args) => {
|
|
82
|
+
return await ctx.db
|
|
83
|
+
.query("tasks")
|
|
84
|
+
.withIndex("by_user", (q) => q.eq("userId", args.userId))
|
|
85
|
+
.order("desc")
|
|
86
|
+
.collect();
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Mutations
|
|
92
|
+
|
|
93
|
+
Mutations modify the database and are transactional:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { mutation } from "./_generated/server";
|
|
97
|
+
import { v } from "convex/values";
|
|
98
|
+
import { ConvexError } from "convex/values";
|
|
99
|
+
|
|
100
|
+
export const createTask = mutation({
|
|
101
|
+
args: {
|
|
102
|
+
title: v.string(),
|
|
103
|
+
userId: v.id("users"),
|
|
104
|
+
},
|
|
105
|
+
returns: v.id("tasks"),
|
|
106
|
+
handler: async (ctx, args) => {
|
|
107
|
+
// Validate user exists
|
|
108
|
+
const user = await ctx.db.get("users", args.userId);
|
|
109
|
+
if (!user) {
|
|
110
|
+
throw new ConvexError("User not found");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return await ctx.db.insert("tasks", {
|
|
114
|
+
title: args.title,
|
|
115
|
+
userId: args.userId,
|
|
116
|
+
completed: false,
|
|
117
|
+
createdAt: Date.now(),
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
export const deleteTask = mutation({
|
|
123
|
+
args: { taskId: v.id("tasks") },
|
|
124
|
+
returns: v.null(),
|
|
125
|
+
handler: async (ctx, args) => {
|
|
126
|
+
await ctx.db.delete("tasks", args.taskId);
|
|
127
|
+
return null;
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Actions
|
|
133
|
+
|
|
134
|
+
Actions can call external APIs but have no direct database access:
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
"use node";
|
|
138
|
+
|
|
139
|
+
import { action } from "./_generated/server";
|
|
140
|
+
import { v } from "convex/values";
|
|
141
|
+
import { api, internal } from "./_generated/api";
|
|
142
|
+
|
|
143
|
+
export const sendEmail = action({
|
|
144
|
+
args: {
|
|
145
|
+
to: v.string(),
|
|
146
|
+
subject: v.string(),
|
|
147
|
+
body: v.string(),
|
|
148
|
+
},
|
|
149
|
+
returns: v.object({ success: v.boolean() }),
|
|
150
|
+
handler: async (ctx, args) => {
|
|
151
|
+
// Call external API
|
|
152
|
+
const response = await fetch("https://api.email.com/send", {
|
|
153
|
+
method: "POST",
|
|
154
|
+
headers: { "Content-Type": "application/json" },
|
|
155
|
+
body: JSON.stringify(args),
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
return { success: response.ok };
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Action calling queries and mutations
|
|
163
|
+
export const processOrder = action({
|
|
164
|
+
args: { orderId: v.id("orders") },
|
|
165
|
+
returns: v.null(),
|
|
166
|
+
handler: async (ctx, args) => {
|
|
167
|
+
// Read data via query
|
|
168
|
+
const order = await ctx.runQuery(api.orders.get, { orderId: args.orderId });
|
|
169
|
+
|
|
170
|
+
if (!order) {
|
|
171
|
+
throw new Error("Order not found");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Call external payment API
|
|
175
|
+
const paymentResult = await processPayment(order);
|
|
176
|
+
|
|
177
|
+
// Update database via mutation
|
|
178
|
+
await ctx.runMutation(internal.orders.updateStatus, {
|
|
179
|
+
orderId: args.orderId,
|
|
180
|
+
status: paymentResult.success ? "paid" : "failed",
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
return null;
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### HTTP Actions
|
|
189
|
+
|
|
190
|
+
HTTP actions handle webhooks and external requests:
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
// convex/http.ts
|
|
194
|
+
import { httpRouter } from "convex/server";
|
|
195
|
+
import { httpAction } from "./_generated/server";
|
|
196
|
+
import { api, internal } from "./_generated/api";
|
|
197
|
+
|
|
198
|
+
const http = httpRouter();
|
|
199
|
+
|
|
200
|
+
// Webhook endpoint
|
|
201
|
+
http.route({
|
|
202
|
+
path: "/webhooks/stripe",
|
|
203
|
+
method: "POST",
|
|
204
|
+
handler: httpAction(async (ctx, request) => {
|
|
205
|
+
const signature = request.headers.get("stripe-signature");
|
|
206
|
+
const body = await request.text();
|
|
207
|
+
|
|
208
|
+
// Verify webhook signature
|
|
209
|
+
if (!verifyStripeSignature(body, signature)) {
|
|
210
|
+
return new Response("Invalid signature", { status: 401 });
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const event = JSON.parse(body);
|
|
214
|
+
|
|
215
|
+
// Process webhook
|
|
216
|
+
await ctx.runMutation(internal.payments.handleWebhook, {
|
|
217
|
+
eventType: event.type,
|
|
218
|
+
data: event.data,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
return new Response("OK", { status: 200 });
|
|
222
|
+
}),
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// API endpoint
|
|
226
|
+
http.route({
|
|
227
|
+
path: "/api/users/:userId",
|
|
228
|
+
method: "GET",
|
|
229
|
+
handler: httpAction(async (ctx, request) => {
|
|
230
|
+
const url = new URL(request.url);
|
|
231
|
+
const userId = url.pathname.split("/").pop();
|
|
232
|
+
|
|
233
|
+
const user = await ctx.runQuery(api.users.get, {
|
|
234
|
+
userId: userId as Id<"users">,
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
if (!user) {
|
|
238
|
+
return new Response("Not found", { status: 404 });
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return Response.json(user);
|
|
242
|
+
}),
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
export default http;
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Internal Functions
|
|
249
|
+
|
|
250
|
+
Use internal functions for sensitive operations:
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
import {
|
|
254
|
+
internalMutation,
|
|
255
|
+
internalQuery,
|
|
256
|
+
internalAction,
|
|
257
|
+
} from "./_generated/server";
|
|
258
|
+
import { v } from "convex/values";
|
|
259
|
+
|
|
260
|
+
// Only callable from other Convex functions
|
|
261
|
+
export const _updateUserCredits = internalMutation({
|
|
262
|
+
args: {
|
|
263
|
+
userId: v.id("users"),
|
|
264
|
+
amount: v.number(),
|
|
265
|
+
},
|
|
266
|
+
returns: v.null(),
|
|
267
|
+
handler: async (ctx, args) => {
|
|
268
|
+
const user = await ctx.db.get("users", args.userId);
|
|
269
|
+
if (!user) return null;
|
|
270
|
+
|
|
271
|
+
await ctx.db.patch("users", args.userId, {
|
|
272
|
+
credits: (user.credits || 0) + args.amount,
|
|
273
|
+
});
|
|
274
|
+
return null;
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
// Call internal function from action
|
|
279
|
+
export const purchaseCredits = action({
|
|
280
|
+
args: { userId: v.id("users"), amount: v.number() },
|
|
281
|
+
returns: v.null(),
|
|
282
|
+
handler: async (ctx, args) => {
|
|
283
|
+
// Process payment externally
|
|
284
|
+
await processPayment(args.amount);
|
|
285
|
+
|
|
286
|
+
// Update credits via internal mutation
|
|
287
|
+
await ctx.runMutation(internal.users._updateUserCredits, {
|
|
288
|
+
userId: args.userId,
|
|
289
|
+
amount: args.amount,
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
return null;
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Scheduling Functions
|
|
298
|
+
|
|
299
|
+
Schedule functions to run later:
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
import { mutation, internalMutation } from "./_generated/server";
|
|
303
|
+
import { v } from "convex/values";
|
|
304
|
+
import { internal } from "./_generated/api";
|
|
305
|
+
|
|
306
|
+
export const scheduleReminder = mutation({
|
|
307
|
+
args: {
|
|
308
|
+
userId: v.id("users"),
|
|
309
|
+
message: v.string(),
|
|
310
|
+
delayMs: v.number(),
|
|
311
|
+
},
|
|
312
|
+
returns: v.id("_scheduled_functions"),
|
|
313
|
+
handler: async (ctx, args) => {
|
|
314
|
+
return await ctx.scheduler.runAfter(
|
|
315
|
+
args.delayMs,
|
|
316
|
+
internal.notifications.sendReminder,
|
|
317
|
+
{ userId: args.userId, message: args.message },
|
|
318
|
+
);
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
export const sendReminder = internalMutation({
|
|
323
|
+
args: {
|
|
324
|
+
userId: v.id("users"),
|
|
325
|
+
message: v.string(),
|
|
326
|
+
},
|
|
327
|
+
returns: v.null(),
|
|
328
|
+
handler: async (ctx, args) => {
|
|
329
|
+
await ctx.db.insert("notifications", {
|
|
330
|
+
userId: args.userId,
|
|
331
|
+
message: args.message,
|
|
332
|
+
sentAt: Date.now(),
|
|
333
|
+
});
|
|
334
|
+
return null;
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## Examples
|
|
340
|
+
|
|
341
|
+
### Complete Function File
|
|
342
|
+
|
|
343
|
+
```typescript
|
|
344
|
+
// convex/messages.ts
|
|
345
|
+
import { query, mutation, internalMutation } from "./_generated/server";
|
|
346
|
+
import { v } from "convex/values";
|
|
347
|
+
import { ConvexError } from "convex/values";
|
|
348
|
+
import { internal } from "./_generated/api";
|
|
349
|
+
|
|
350
|
+
const messageValidator = v.object({
|
|
351
|
+
_id: v.id("messages"),
|
|
352
|
+
_creationTime: v.number(),
|
|
353
|
+
channelId: v.id("channels"),
|
|
354
|
+
authorId: v.id("users"),
|
|
355
|
+
content: v.string(),
|
|
356
|
+
editedAt: v.optional(v.number()),
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// Public query
|
|
360
|
+
export const list = query({
|
|
361
|
+
args: {
|
|
362
|
+
channelId: v.id("channels"),
|
|
363
|
+
limit: v.optional(v.number()),
|
|
364
|
+
},
|
|
365
|
+
returns: v.array(messageValidator),
|
|
366
|
+
handler: async (ctx, args) => {
|
|
367
|
+
const limit = args.limit ?? 50;
|
|
368
|
+
return await ctx.db
|
|
369
|
+
.query("messages")
|
|
370
|
+
.withIndex("by_channel", (q) => q.eq("channelId", args.channelId))
|
|
371
|
+
.order("desc")
|
|
372
|
+
.take(limit);
|
|
373
|
+
},
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
// Public mutation
|
|
377
|
+
export const send = mutation({
|
|
378
|
+
args: {
|
|
379
|
+
channelId: v.id("channels"),
|
|
380
|
+
authorId: v.id("users"),
|
|
381
|
+
content: v.string(),
|
|
382
|
+
},
|
|
383
|
+
returns: v.id("messages"),
|
|
384
|
+
handler: async (ctx, args) => {
|
|
385
|
+
if (args.content.trim().length === 0) {
|
|
386
|
+
throw new ConvexError("Message cannot be empty");
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const messageId = await ctx.db.insert("messages", {
|
|
390
|
+
channelId: args.channelId,
|
|
391
|
+
authorId: args.authorId,
|
|
392
|
+
content: args.content.trim(),
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
// Schedule notification
|
|
396
|
+
await ctx.scheduler.runAfter(0, internal.messages.notifySubscribers, {
|
|
397
|
+
channelId: args.channelId,
|
|
398
|
+
messageId,
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
return messageId;
|
|
402
|
+
},
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
// Internal mutation
|
|
406
|
+
export const notifySubscribers = internalMutation({
|
|
407
|
+
args: {
|
|
408
|
+
channelId: v.id("channels"),
|
|
409
|
+
messageId: v.id("messages"),
|
|
410
|
+
},
|
|
411
|
+
returns: v.null(),
|
|
412
|
+
handler: async (ctx, args) => {
|
|
413
|
+
// Get channel subscribers and notify them
|
|
414
|
+
const subscribers = await ctx.db
|
|
415
|
+
.query("subscriptions")
|
|
416
|
+
.withIndex("by_channel", (q) => q.eq("channelId", args.channelId))
|
|
417
|
+
.collect();
|
|
418
|
+
|
|
419
|
+
for (const sub of subscribers) {
|
|
420
|
+
await ctx.db.insert("notifications", {
|
|
421
|
+
userId: sub.userId,
|
|
422
|
+
messageId: args.messageId,
|
|
423
|
+
read: false,
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
return null;
|
|
427
|
+
},
|
|
428
|
+
});
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
## Best Practices
|
|
432
|
+
|
|
433
|
+
- Never run `npx convex deploy` unless explicitly instructed
|
|
434
|
+
- Never run any git commands unless explicitly instructed
|
|
435
|
+
- Always define args and returns validators
|
|
436
|
+
- Use queries for read operations (they are cached and reactive)
|
|
437
|
+
- Use mutations for write operations (they are transactional)
|
|
438
|
+
- Use actions only when calling external APIs
|
|
439
|
+
- Use internal functions for sensitive operations
|
|
440
|
+
- Add `"use node";` at the top of action files using Node.js APIs
|
|
441
|
+
- Handle errors with ConvexError for user-facing messages
|
|
442
|
+
|
|
443
|
+
## Common Pitfalls
|
|
444
|
+
|
|
445
|
+
1. **Using actions for database operations** - Use queries/mutations instead
|
|
446
|
+
2. **Calling external APIs from queries/mutations** - Use actions
|
|
447
|
+
3. **Forgetting to add "use node"** - Required for Node.js APIs in actions
|
|
448
|
+
4. **Missing return validators** - Always specify returns
|
|
449
|
+
5. **Not using internal functions for sensitive logic** - Protect with internalMutation
|
|
450
|
+
|
|
451
|
+
## References
|
|
452
|
+
|
|
453
|
+
- Convex Documentation: https://docs.convex.dev/
|
|
454
|
+
- Convex LLMs.txt: https://docs.convex.dev/llms.txt
|
|
455
|
+
- Functions Overview: https://docs.convex.dev/functions
|
|
456
|
+
- Query Functions: https://docs.convex.dev/functions/query-functions
|
|
457
|
+
- Mutation Functions: https://docs.convex.dev/functions/mutation-functions
|
|
458
|
+
- Actions: https://docs.convex.dev/functions/actions
|
|
Binary file
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<g clip-path="url(#clip0_3_23)">
|
|
3
|
+
<g clip-path="url(#clip1_3_23)">
|
|
4
|
+
<path d="M10.0643 12.5735C12.3769 12.3166 14.5572 11.0843 15.7577 9.02756C15.1892 14.1148 9.62646 17.3302 5.08583 15.356C4.66743 15.1746 4.30728 14.8728 4.06013 14.4848C3.03973 12.8825 2.7043 10.8437 3.18626 8.99344C4.56327 11.37 7.3632 12.8267 10.0643 12.5735Z" fill="#F3B01C"/>
|
|
5
|
+
<path d="M3.1018 7.50072C2.16436 9.66714 2.12376 12.2034 3.27303 14.2907C-0.771507 11.2479 -0.72737 4.7362 3.2236 1.72378C3.58904 1.44535 4.02333 1.2801 4.47881 1.25494C6.3519 1.15614 8.25501 1.88006 9.58963 3.22909C6.87799 3.25604 4.23695 4.99308 3.1018 7.50072Z" fill="#8D2676"/>
|
|
6
|
+
<path d="M10.8974 3.89562C9.52924 1.98794 7.38779 0.68921 5.04156 0.649695C9.57686 -1.40888 15.1555 1.92867 15.7629 6.86314C15.8194 7.32119 15.7452 7.78824 15.5421 8.20138C14.6948 9.92223 13.1236 11.2569 11.2876 11.7508C12.6328 9.25579 12.4668 6.20748 10.8974 3.89562Z" fill="#EE342F"/>
|
|
7
|
+
</g>
|
|
8
|
+
</g>
|
|
9
|
+
<defs>
|
|
10
|
+
<clipPath id="clip0_3_23">
|
|
11
|
+
<rect width="16" height="16" fill="white"/>
|
|
12
|
+
</clipPath>
|
|
13
|
+
<clipPath id="clip1_3_23">
|
|
14
|
+
<rect width="16" height="16" fill="white"/>
|
|
15
|
+
</clipPath>
|
|
16
|
+
</defs>
|
|
17
|
+
</svg>
|