Skip to content

Commit e8945a6

Browse files
authored
Merge pull request #46 from get-convex/jordan/more-tweaking-guidelines
Tweak more guidelines
2 parents f9ea121 + 0924f1e commit e8945a6

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

evals/000-fundamentals/009-returns_validator/TASK.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ b. Create a query `getPostWithStatus` that:
3737

3838
c. Create a query `getPostWithAuthor` that:
3939
- Takes a post ID as an argument
40-
- Returns [Doc<"users">, Doc<"posts">]
40+
- Returns an array that contains Doc<"users"> and Doc<"posts">
4141

4242
Define a return validator for each of them.

runner/models/guidelines.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,28 @@ def __init__(self, name: str, children: list):
6262
),
6363
],
6464
),
65+
GuidelineSection(
66+
"validators",
67+
[
68+
Guideline(
69+
"""Below is an example of an array validator:
70+
```typescript
71+
import { mutation } from "./_generated/server";
72+
import { v } from "convex/values";
73+
74+
export default mutation({
75+
args: {
76+
simpleArray: v.array(v.union(v.string(), v.number())),
77+
},
78+
handler: async (ctx, args) => {
79+
//...
80+
},
81+
});
82+
```
83+
"""
84+
)
85+
],
86+
),
6587
GuidelineSection(
6688
"function_registration",
6789
[
@@ -75,7 +97,7 @@ def __init__(self, name: str, children: list):
7597
"You CANNOT register a function through the `api` or `internal` objects."
7698
),
7799
Guideline(
78-
"ALWAYS include argument and return validators for all Convex functions. If a function doesn't return anything, include `returns: v.null()` as its output validator."
100+
"ALWAYS include argument and return validators for all Convex functions. This includes all of `query`, `internalQuery`, `mutation`, `internalMutation`, `action`, and `internalAction`. If a function doesn't return anything, include `returns: v.null()` as its output validator."
79101
),
80102
Guideline(
81103
"If the JavaScript implementation of a Convex function doesn't have a return value, it implicitly returns `null`."
@@ -234,6 +256,7 @@ def __init__(self, name: str, children: list):
234256
Guideline(
235257
"Be strict with types, particularly around id's of documents. For example, if a function takes in an id for a document in the 'users' table, take in `Id<'users'>` rather than `string`."
236258
),
259+
Guideline("Always use `as const` for string literals in discriminated union types."),
237260
],
238261
),
239262
GuidelineSection(

0 commit comments

Comments
 (0)