oneie 3.6.6 → 3.6.11
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/.claude/agents/agent-backend.md +83 -0
- package/.claude/agents/agent-designer.md +97 -0
- package/.claude/agents/agent-director.md +118 -7
- package/.claude/agents/agent-documenter.md +93 -0
- package/.claude/agents/agent-frontend.md +96 -0
- package/.claude/agents/agent-ops.md +182 -25
- package/.claude/agents/agent-problem-solver.md +166 -0
- package/.claude/agents/agent-quality.md +127 -0
- package/.claude/commands/build.md +293 -0
- package/.claude/commands/cascade.md +231 -127
- package/.claude/commands/mcp-toggle.md +93 -0
- package/.claude/commands/onboard.md +179 -0
- package/.claude/commands/one.md +236 -516
- package/.claude/commands/plan.md +394 -80
- package/.claude/commands/release.md +41 -19
- package/.claude/commands/server.md +335 -0
- package/.claude/hooks/root-cleanup.py +75 -0
- package/.claude/skills/INDEX.md +523 -0
- package/.claude/skills/REGISTRY.md +529 -0
- package/.claude/skills/agent-backend-create-mutation.md +319 -0
- package/.claude/skills/agent-designer-create-wireframe.md +341 -0
- package/.claude/skills/agent-frontend-create-page.md +413 -0
- package/.claude/skills/agents/README.md +238 -0
- package/dist/clone-web.js +1 -1
- package/dist/clone-web.js.map +1 -1
- package/folders.yaml +1 -1
- package/one/.obsidian/workspace.json +38 -38
- package/one/connections/api/queries-reference.md +842 -0
- package/one/connections/api-reference.md +1011 -0
- package/one/connections/integration-examples.md +875 -0
- package/one/connections/integration-guide.md +869 -0
- package/one/connections/integration-phase2.md +736 -0
- package/one/events/API_ROUTES_FIXES_SUMMARY.md +262 -0
- package/one/events/ASTRO-INTEGRATION-EXAMPLES.md +636 -0
- package/one/events/BEFORE_AFTER_COMPARISON.md +960 -0
- package/one/events/CONNECTIONS_DEMO.md +501 -0
- package/one/events/DELIVERABLES.md +432 -0
- package/one/events/DEMO-GROUPS-PAGE.md +392 -0
- package/one/events/DEMO-TESTING-SUMMARY.md +518 -0
- package/one/events/DEMO_COMPONENTS.md +487 -0
- package/one/events/DEMO_HOOKS_INDEX.md +334 -0
- package/one/events/DEMO_INFRASTRUCTURE.md +905 -0
- package/one/events/DEMO_INFRASTRUCTURE_SUMMARY.md +570 -0
- package/one/events/DEMO_INTEGRATION_CHECKLIST.md +431 -0
- package/one/events/DEMO_QUICK_REFERENCE.md +441 -0
- package/one/events/DEMO_SETUP.md +476 -0
- package/one/events/EFFECT_TS_API_PATTERN.md +478 -0
- package/one/events/GROUPS_DEMO_IMPLEMENTATION.md +414 -0
- package/one/events/HOOKS-DEMO.md +441 -0
- package/one/events/ONTOLOGY-HOOKS-README.md +700 -0
- package/one/events/ONTOLOGY-INTEGRATION-MANIFEST.md +365 -0
- package/one/events/QA-CHECKLIST.md +674 -0
- package/one/events/QUICK-START-ONTOLOGY.md +408 -0
- package/one/events/SEARCH_DEMO_CODE_REFERENCE.md +639 -0
- package/one/events/SEARCH_DEMO_DELIVERY.md +415 -0
- package/one/events/SEARCH_DEMO_SUMMARY.md +303 -0
- package/one/events/SEARCH_DEMO_VISUAL_GUIDE.md +381 -0
- package/one/events/TEST-PLAN-INDEX.md +346 -0
- package/one/events/TEST-PLAN.md +1417 -0
- package/one/events/TESTING-DELIVERY.txt +372 -0
- package/one/events/TRANSITIONS-QUICK-START.md +141 -0
- package/one/events/TYPESCRIPT_FIXES.md +152 -0
- package/one/events/TYPESCRIPT_FIXES_COMPLETE.txt +412 -0
- package/one/events/TYPESCRIPT_FIXES_INDEX.md +341 -0
- package/one/events/VIEW-TRANSITIONS.md +428 -0
- package/one/events/backend-integration-tests.md +606 -0
- package/one/events/backend-structure-diagram.txt +393 -0
- package/one/events/backend-structure-summary.txt +269 -0
- package/one/events/cloudflare-pages-infrastructure-setup.md +264 -0
- package/one/events/convex-analysis-index.md +304 -0
- package/one/events/convex-structure-analysis.md +700 -0
- package/one/events/design-spec-complete.md +208 -0
- package/one/events/ontology-test-examples.md +562 -0
- package/one/events/phase1-backend-implementation-complete.md +518 -0
- package/one/events/test-dashboard.md +345 -0
- package/one/events/test-index.md +361 -0
- package/one/events/test-report-ontology.md +582 -0
- package/one/events/testing-summary.md +344 -0
- package/one/groups/features.md +2878 -0
- package/one/groups/strategy copy.md +869 -0
- package/one/knowledge/backend-api-reference.md +710 -0
- package/one/knowledge/documentation-summary.md +285 -0
- package/one/knowledge/lessons-learned.md +294 -4
- package/one/knowledge/ontology-visual-guide.md +360 -0
- package/one/knowledge/ontology.md +9 -17
- package/one/things/demo-accessibility-animations.md +999 -0
- package/one/things/demo-components.md +1304 -0
- package/one/things/demo-design-summary.md +629 -0
- package/one/things/demo-design-system.md +919 -0
- package/one/things/demo-page-layouts.md +989 -0
- package/one/things/designs/accessibility-audit.md +790 -0
- package/one/things/designs/component-specifications.md +757 -0
- package/one/things/designs/design-overview.md +318 -0
- package/one/things/designs/design-tokens.md +414 -0
- package/one/things/designs/wireframes-dashboard.md +653 -0
- package/one/things/docs/api-requests.md +923 -0
- package/one/things/features/0 All Features.md +2 -0
- package/one/things/implementation/backend-guide.md +412 -0
- package/one/things/plans/2-backend-agnostic-frontend.md +11 -8
- package/one/things/plans/ai-elements.md +1259 -0
- package/one/things/plans/ai-integration.md +947 -0
- package/one/things/plans/ai-sdk.md +761 -0
- package/one/things/plans/app.md +1 -1
- package/one/things/plans/architecture-summary.md +283 -0
- package/one/things/plans/async-ai-agents.md +215 -0
- package/one/things/plans/backend-agnostic-frontend.md +11 -6
- package/one/things/plans/backend-cleanup-quickstart.md +346 -0
- package/one/things/plans/backend-ontology-conformance.md +416 -0
- package/one/things/plans/backend-status.md +541 -0
- package/one/things/plans/backend-structure.md +799 -0
- package/one/things/plans/backend-target-structure.md +438 -0
- package/one/things/plans/backend.md +1133 -0
- package/one/things/plans/better-auth-any-backend.md +11 -11
- package/one/things/plans/cli-updates-required.md +280 -0
- package/one/things/plans/complete-step-by-step.md +1302 -0
- package/one/things/plans/convex-agents.md +1005 -0
- package/one/things/plans/deployment-architecture.md +426 -0
- package/one/things/plans/development-plan.md +1220 -0
- package/one/things/plans/effect.md +808 -48
- package/one/things/plans/integrate-frontend-and-backend.md +579 -0
- package/one/things/plans/mcp-clear-context-prompt.md +60 -0
- package/one/things/plans/mcp-simple.md +228 -0
- package/one/things/plans/one.md +8 -7
- package/one/things/plans/ontology-6-dimensions.md +20 -14
- package/one/things/plans/quick-wins.md +1273 -0
- package/one/things/plans/readme-backend-cleanup.md +361 -0
- package/one/things/plans/separate-demo.md +830 -0
- package/one/things/plans/separate.md +3 -3
- package/one/things/plans/sequence.md +1897 -0
- package/one/things/plans/sync-checklist.md +321 -0
- package/one/things/plans/unified-implementation-plan.md +3 -3
- package/one/things/plans/update-demos.md +513 -0
- package/package.json +1 -1
- package/.claude/agents/backend-specialist.md +0 -169
- package/.claude/agents/designer.md +0 -216
- package/.claude/agents/frontend-specialist.md +0 -236
- package/.claude/commands/done.md +0 -35
- package/.claude/commands/infer.md +0 -138
- package/.claude/commands/next.md +0 -53
- package/.claude/commands/one copy.md +0 -565
- package/.claude/commands/one-template.md +0 -106
- package/.claude/commands/one-v1.md +0 -609
- package/.claude/hooks/__pycache__/knowledge-post.cpython-313.pyc +0 -0
- package/.claude/hooks/__pycache__/knowledge-pre.cpython-313.pyc +0 -0
- package/.claude/hooks/__pycache__/todo.cpython-313.pyc +0 -0
- package/one/groups/nine-padel-customers.md +0 -138
- package/one/groups/nine-padel-data-structure.md +0 -167
- package/one/groups/nine-padel-ontology-specification.md +0 -359
- package/one/groups/nine-padel-ontology.md +0 -143
- package/one/groups/nine-padel-strategy.md +0 -234
- package/one/groups/nine-padel.md +0 -211
- package/one/groups/nine-padle-contents.baked.md +0 -1252
- package/one/groups/nine-padle-contents.md +0 -6
- package/one/things/features/1-1-agent-prompts/design.md +0 -470
- package/one/things/features/1-1-agent-prompts/tests.md +0 -264
- package/one/things/features/1-2-yaml-orchestrator/design.md +0 -497
- package/one/things/features/1-2-yaml-orchestrator/tests.md +0 -227
- package/one/things/features/1-3-event-coordination/design.md +0 -544
- package/one/things/features/1-3-event-coordination/tests.md +0 -223
- package/one/things/features/1-4-knowledge-management/design.md +0 -609
- package/one/things/features/1-4-knowledge-management/tests.md +0 -195
- package/one/things/features/1-5-quality-loops/design.md +0 -797
- package/one/things/features/1-5-quality-loops/tests.md +0 -212
- package/one/things/features/1-6-numbering-structure/design.md +0 -610
- package/one/things/features/1-6-numbering-structure/tests.md +0 -213
- package/one/things/features/dataprovider-interface/1-tests.md +0 -1522
|
@@ -0,0 +1,1011 @@
|
|
|
1
|
+
# ONE Platform API Reference
|
|
2
|
+
|
|
3
|
+
**Version:** 1.0.0
|
|
4
|
+
**Created:** 2025-01-25
|
|
5
|
+
**Purpose:** Complete API documentation for all Convex queries and mutations
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Authentication
|
|
10
|
+
|
|
11
|
+
All API operations require authentication via Better Auth. Include session token in headers:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
Authorization: Bearer <session-token>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Authentication Methods:**
|
|
18
|
+
- Email/Password
|
|
19
|
+
- OAuth (GitHub, Google)
|
|
20
|
+
- Magic Links
|
|
21
|
+
- 2FA (TOTP + Backup codes)
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Response Format
|
|
26
|
+
|
|
27
|
+
### Success Response
|
|
28
|
+
```typescript
|
|
29
|
+
{
|
|
30
|
+
data: <result>,
|
|
31
|
+
_id: Id<"table">,
|
|
32
|
+
_creationTime: number
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Error Response
|
|
37
|
+
```typescript
|
|
38
|
+
{
|
|
39
|
+
error: {
|
|
40
|
+
message: string,
|
|
41
|
+
code: string,
|
|
42
|
+
details?: any
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Groups API (Dimension 1: Multi-Tenant Isolation)
|
|
50
|
+
|
|
51
|
+
Groups are the foundation of multi-tenancy in ONE Platform. Every entity, connection, event, and knowledge item belongs to a group.
|
|
52
|
+
|
|
53
|
+
### Queries
|
|
54
|
+
|
|
55
|
+
#### `getBySlug`
|
|
56
|
+
Get a group by its URL slug.
|
|
57
|
+
|
|
58
|
+
**Arguments:**
|
|
59
|
+
```typescript
|
|
60
|
+
{
|
|
61
|
+
slug: string // URL-friendly identifier
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Returns:** `Group | null`
|
|
66
|
+
|
|
67
|
+
**Example:**
|
|
68
|
+
```typescript
|
|
69
|
+
const group = await convex.query(api.queries.groups.getBySlug, {
|
|
70
|
+
slug: "emmas-lemonade"
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
#### `getById`
|
|
77
|
+
Get a group by ID.
|
|
78
|
+
|
|
79
|
+
**Arguments:**
|
|
80
|
+
```typescript
|
|
81
|
+
{
|
|
82
|
+
groupId: Id<"groups">
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Returns:** `Group | null`
|
|
87
|
+
|
|
88
|
+
**Example:**
|
|
89
|
+
```typescript
|
|
90
|
+
const group = await convex.query(api.queries.groups.getById, {
|
|
91
|
+
groupId: "j1x7k2m3n4p5q6r7s8t9"
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
#### `list`
|
|
98
|
+
List groups with optional filters.
|
|
99
|
+
|
|
100
|
+
**Arguments:**
|
|
101
|
+
```typescript
|
|
102
|
+
{
|
|
103
|
+
type?: "friend_circle" | "business" | "community" | "dao" | "government" | "organization",
|
|
104
|
+
status?: "active" | "archived",
|
|
105
|
+
limit?: number
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Returns:** `Group[]`
|
|
110
|
+
|
|
111
|
+
**Example:**
|
|
112
|
+
```typescript
|
|
113
|
+
const businesses = await convex.query(api.queries.groups.list, {
|
|
114
|
+
type: "business",
|
|
115
|
+
status: "active",
|
|
116
|
+
limit: 10
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
#### `getSubgroups`
|
|
123
|
+
Get direct children (non-recursive) of a parent group.
|
|
124
|
+
|
|
125
|
+
**Arguments:**
|
|
126
|
+
```typescript
|
|
127
|
+
{
|
|
128
|
+
parentGroupId: Id<"groups">
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Returns:** `Group[]`
|
|
133
|
+
|
|
134
|
+
**Example:**
|
|
135
|
+
```typescript
|
|
136
|
+
const departments = await convex.query(api.queries.groups.getSubgroups, {
|
|
137
|
+
parentGroupId: acmeCorpId
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
#### `getHierarchy`
|
|
144
|
+
Get entire group hierarchy recursively (all descendants).
|
|
145
|
+
|
|
146
|
+
**Arguments:**
|
|
147
|
+
```typescript
|
|
148
|
+
{
|
|
149
|
+
rootGroupId: Id<"groups">,
|
|
150
|
+
maxDepth?: number // Default: 10, prevents infinite recursion
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Returns:** `Array<Group & { depth: number, parentId: string }>`
|
|
155
|
+
|
|
156
|
+
**Example:**
|
|
157
|
+
```typescript
|
|
158
|
+
const hierarchy = await convex.query(api.queries.groups.getHierarchy, {
|
|
159
|
+
rootGroupId: acmeCorpId,
|
|
160
|
+
maxDepth: 5
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
#### `getGroupPath`
|
|
167
|
+
Get breadcrumb trail from root to specific group.
|
|
168
|
+
|
|
169
|
+
**Arguments:**
|
|
170
|
+
```typescript
|
|
171
|
+
{
|
|
172
|
+
groupId: Id<"groups">
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**Returns:** `Group[]` (ordered: [root, parent, grandparent, ..., targetGroup])
|
|
177
|
+
|
|
178
|
+
**Example:**
|
|
179
|
+
```typescript
|
|
180
|
+
const path = await convex.query(api.queries.groups.getGroupPath, {
|
|
181
|
+
groupId: backendTeamId
|
|
182
|
+
});
|
|
183
|
+
// Returns: [AcmeCorp, Engineering, BackendTeam]
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
#### `isDescendantOf`
|
|
189
|
+
Check if a group is a descendant of another group (useful for permissions).
|
|
190
|
+
|
|
191
|
+
**Arguments:**
|
|
192
|
+
```typescript
|
|
193
|
+
{
|
|
194
|
+
groupId: Id<"groups">,
|
|
195
|
+
ancestorGroupId: Id<"groups">
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**Returns:** `boolean`
|
|
200
|
+
|
|
201
|
+
**Example:**
|
|
202
|
+
```typescript
|
|
203
|
+
const hasAccess = await convex.query(api.queries.groups.isDescendantOf, {
|
|
204
|
+
groupId: backendTeamId,
|
|
205
|
+
ancestorGroupId: acmeCorpId
|
|
206
|
+
});
|
|
207
|
+
// Returns: true (BackendTeam → Engineering → AcmeCorp)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
#### `getEntitiesInHierarchy`
|
|
213
|
+
Get all entities in group + all subgroups (recursive).
|
|
214
|
+
|
|
215
|
+
**Arguments:**
|
|
216
|
+
```typescript
|
|
217
|
+
{
|
|
218
|
+
rootGroupId: Id<"groups">,
|
|
219
|
+
entityType?: string, // Filter by entity type
|
|
220
|
+
limit?: number
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Returns:** `Entity[]`
|
|
225
|
+
|
|
226
|
+
**Example:**
|
|
227
|
+
```typescript
|
|
228
|
+
const allProjects = await convex.query(api.queries.groups.getEntitiesInHierarchy, {
|
|
229
|
+
rootGroupId: acmeCorpId,
|
|
230
|
+
entityType: "project",
|
|
231
|
+
limit: 50
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
#### `getStats`
|
|
238
|
+
Get statistics for a group (optionally including subgroups).
|
|
239
|
+
|
|
240
|
+
**Arguments:**
|
|
241
|
+
```typescript
|
|
242
|
+
{
|
|
243
|
+
groupId: Id<"groups">,
|
|
244
|
+
includeSubgroups?: boolean
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**Returns:**
|
|
249
|
+
```typescript
|
|
250
|
+
{
|
|
251
|
+
group: Group,
|
|
252
|
+
stats: {
|
|
253
|
+
members: number,
|
|
254
|
+
entities: number,
|
|
255
|
+
connections: number,
|
|
256
|
+
events: number,
|
|
257
|
+
knowledge: number,
|
|
258
|
+
subgroups: number
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**Example:**
|
|
264
|
+
```typescript
|
|
265
|
+
const stats = await convex.query(api.queries.groups.getStats, {
|
|
266
|
+
groupId: acmeCorpId,
|
|
267
|
+
includeSubgroups: true
|
|
268
|
+
});
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
#### `search`
|
|
274
|
+
Search groups by name or slug.
|
|
275
|
+
|
|
276
|
+
**Arguments:**
|
|
277
|
+
```typescript
|
|
278
|
+
{
|
|
279
|
+
query: string,
|
|
280
|
+
type?: "friend_circle" | "business" | "community" | "dao" | "government" | "organization",
|
|
281
|
+
visibility?: "public" | "private",
|
|
282
|
+
limit?: number
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
**Returns:** `Group[]`
|
|
287
|
+
|
|
288
|
+
**Example:**
|
|
289
|
+
```typescript
|
|
290
|
+
const results = await convex.query(api.queries.groups.search, {
|
|
291
|
+
query: "acme",
|
|
292
|
+
type: "business",
|
|
293
|
+
visibility: "private",
|
|
294
|
+
limit: 5
|
|
295
|
+
});
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
### Mutations
|
|
301
|
+
|
|
302
|
+
#### `create`
|
|
303
|
+
Create a new group.
|
|
304
|
+
|
|
305
|
+
**Arguments:**
|
|
306
|
+
```typescript
|
|
307
|
+
{
|
|
308
|
+
slug: string, // URL-friendly identifier (must be unique)
|
|
309
|
+
name: string, // Display name
|
|
310
|
+
type: "friend_circle" | "business" | "community" | "dao" | "government" | "organization",
|
|
311
|
+
parentGroupId?: Id<"groups">, // For hierarchical nesting
|
|
312
|
+
description?: string,
|
|
313
|
+
metadata?: any,
|
|
314
|
+
settings?: {
|
|
315
|
+
visibility: "public" | "private",
|
|
316
|
+
joinPolicy: "open" | "invite_only" | "approval_required",
|
|
317
|
+
plan?: "starter" | "pro" | "enterprise",
|
|
318
|
+
limits?: {
|
|
319
|
+
users: number,
|
|
320
|
+
storage: number, // GB
|
|
321
|
+
apiCalls: number
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
**Returns:** `Id<"groups">`
|
|
328
|
+
|
|
329
|
+
**Example:**
|
|
330
|
+
```typescript
|
|
331
|
+
const groupId = await convex.mutation(api.mutations.groups.create, {
|
|
332
|
+
slug: "acme-corp",
|
|
333
|
+
name: "Acme Corporation",
|
|
334
|
+
type: "organization",
|
|
335
|
+
description: "Enterprise SaaS company",
|
|
336
|
+
settings: {
|
|
337
|
+
visibility: "private",
|
|
338
|
+
joinPolicy: "invite_only",
|
|
339
|
+
plan: "enterprise",
|
|
340
|
+
limits: {
|
|
341
|
+
users: 100,
|
|
342
|
+
storage: 1000,
|
|
343
|
+
apiCalls: 1000000
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
**Default Settings by Type:**
|
|
350
|
+
- `friend_circle`: private, invite_only, starter
|
|
351
|
+
- `business`: private, invite_only, pro
|
|
352
|
+
- `community`: public, approval_required, pro
|
|
353
|
+
- `dao`: public, open, pro
|
|
354
|
+
- `government`: public, approval_required, enterprise
|
|
355
|
+
- `organization`: private, invite_only, starter
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
#### `update`
|
|
360
|
+
Update an existing group.
|
|
361
|
+
|
|
362
|
+
**Arguments:**
|
|
363
|
+
```typescript
|
|
364
|
+
{
|
|
365
|
+
groupId: Id<"groups">,
|
|
366
|
+
name?: string,
|
|
367
|
+
description?: string,
|
|
368
|
+
metadata?: any,
|
|
369
|
+
settings?: {
|
|
370
|
+
visibility: "public" | "private",
|
|
371
|
+
joinPolicy: "open" | "invite_only" | "approval_required",
|
|
372
|
+
plan?: "starter" | "pro" | "enterprise",
|
|
373
|
+
limits?: {
|
|
374
|
+
users: number,
|
|
375
|
+
storage: number,
|
|
376
|
+
apiCalls: number
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**Returns:** `Id<"groups">`
|
|
383
|
+
|
|
384
|
+
**Example:**
|
|
385
|
+
```typescript
|
|
386
|
+
await convex.mutation(api.mutations.groups.update, {
|
|
387
|
+
groupId: acmeCorpId,
|
|
388
|
+
settings: {
|
|
389
|
+
plan: "enterprise",
|
|
390
|
+
limits: {
|
|
391
|
+
users: 200,
|
|
392
|
+
storage: 2000,
|
|
393
|
+
apiCalls: 2000000
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
---
|
|
400
|
+
|
|
401
|
+
#### `archive`
|
|
402
|
+
Archive a group (soft delete - maintains audit trail).
|
|
403
|
+
|
|
404
|
+
**Arguments:**
|
|
405
|
+
```typescript
|
|
406
|
+
{
|
|
407
|
+
groupId: Id<"groups">
|
|
408
|
+
}
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
**Returns:** `Id<"groups">`
|
|
412
|
+
|
|
413
|
+
**Example:**
|
|
414
|
+
```typescript
|
|
415
|
+
await convex.mutation(api.mutations.groups.archive, {
|
|
416
|
+
groupId: oldProjectId
|
|
417
|
+
});
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
#### `restore`
|
|
423
|
+
Restore an archived group.
|
|
424
|
+
|
|
425
|
+
**Arguments:**
|
|
426
|
+
```typescript
|
|
427
|
+
{
|
|
428
|
+
groupId: Id<"groups">
|
|
429
|
+
}
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
**Returns:** `Id<"groups">`
|
|
433
|
+
|
|
434
|
+
**Example:**
|
|
435
|
+
```typescript
|
|
436
|
+
await convex.mutation(api.mutations.groups.restore, {
|
|
437
|
+
groupId: oldProjectId
|
|
438
|
+
});
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
## Entities API (Dimension 3: Things)
|
|
444
|
+
|
|
445
|
+
Entities represent all "things" in the system - users, content, products, courses, etc.
|
|
446
|
+
|
|
447
|
+
### Queries
|
|
448
|
+
|
|
449
|
+
#### `list`
|
|
450
|
+
List entities in a group with optional filters.
|
|
451
|
+
|
|
452
|
+
**Arguments:**
|
|
453
|
+
```typescript
|
|
454
|
+
{
|
|
455
|
+
groupId: Id<"groups">,
|
|
456
|
+
type?: string, // Entity type from ontology
|
|
457
|
+
status?: string, // draft, active, published, archived, inactive
|
|
458
|
+
limit?: number
|
|
459
|
+
}
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
**Returns:** `Entity[]`
|
|
463
|
+
|
|
464
|
+
**Example:**
|
|
465
|
+
```typescript
|
|
466
|
+
const courses = await convex.query(api.queries.entities.list, {
|
|
467
|
+
groupId: acmeCorpId,
|
|
468
|
+
type: "course",
|
|
469
|
+
status: "published",
|
|
470
|
+
limit: 20
|
|
471
|
+
});
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
**Performance:** Uses `group_type` index for efficient filtering.
|
|
475
|
+
|
|
476
|
+
---
|
|
477
|
+
|
|
478
|
+
#### `getById`
|
|
479
|
+
Get a single entity by ID with optional group validation.
|
|
480
|
+
|
|
481
|
+
**Arguments:**
|
|
482
|
+
```typescript
|
|
483
|
+
{
|
|
484
|
+
entityId: Id<"entities">,
|
|
485
|
+
groupId?: Id<"groups"> // Optional security validation
|
|
486
|
+
}
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
**Returns:** `Entity | null`
|
|
490
|
+
|
|
491
|
+
**Example:**
|
|
492
|
+
```typescript
|
|
493
|
+
const course = await convex.query(api.queries.entities.getById, {
|
|
494
|
+
entityId: courseId,
|
|
495
|
+
groupId: acmeCorpId // Ensures entity belongs to expected group
|
|
496
|
+
});
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
---
|
|
500
|
+
|
|
501
|
+
#### `search`
|
|
502
|
+
Search entities by name (case-insensitive).
|
|
503
|
+
|
|
504
|
+
**Arguments:**
|
|
505
|
+
```typescript
|
|
506
|
+
{
|
|
507
|
+
groupId: Id<"groups">,
|
|
508
|
+
query: string,
|
|
509
|
+
type?: string,
|
|
510
|
+
limit?: number
|
|
511
|
+
}
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
**Returns:** `Entity[]`
|
|
515
|
+
|
|
516
|
+
**Example:**
|
|
517
|
+
```typescript
|
|
518
|
+
const results = await convex.query(api.queries.entities.search, {
|
|
519
|
+
groupId: acmeCorpId,
|
|
520
|
+
query: "typescript",
|
|
521
|
+
type: "course",
|
|
522
|
+
limit: 10
|
|
523
|
+
});
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
---
|
|
527
|
+
|
|
528
|
+
#### `getWithConnections`
|
|
529
|
+
Get entity with all its connections (both FROM and TO).
|
|
530
|
+
|
|
531
|
+
**Arguments:**
|
|
532
|
+
```typescript
|
|
533
|
+
{
|
|
534
|
+
entityId: Id<"entities">,
|
|
535
|
+
groupId?: Id<"groups">
|
|
536
|
+
}
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
**Returns:**
|
|
540
|
+
```typescript
|
|
541
|
+
{
|
|
542
|
+
entity: Entity,
|
|
543
|
+
connectionsFrom: Connection[],
|
|
544
|
+
connectionsTo: Connection[]
|
|
545
|
+
} | null
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
**Example:**
|
|
549
|
+
```typescript
|
|
550
|
+
const graph = await convex.query(api.queries.entities.getWithConnections, {
|
|
551
|
+
entityId: userId
|
|
552
|
+
});
|
|
553
|
+
// Returns: { entity, connectionsFrom: [owns, created], connectionsTo: [enrolled_in] }
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
**Use Case:** Relationship visualization, graph queries
|
|
557
|
+
|
|
558
|
+
---
|
|
559
|
+
|
|
560
|
+
#### `getActivity`
|
|
561
|
+
Get entity activity timeline (all events where entity is target).
|
|
562
|
+
|
|
563
|
+
**Arguments:**
|
|
564
|
+
```typescript
|
|
565
|
+
{
|
|
566
|
+
entityId: Id<"entities">,
|
|
567
|
+
limit?: number
|
|
568
|
+
}
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
**Returns:** `Event[]` (sorted by timestamp, most recent first)
|
|
572
|
+
|
|
573
|
+
**Example:**
|
|
574
|
+
```typescript
|
|
575
|
+
const activity = await convex.query(api.queries.entities.getActivity, {
|
|
576
|
+
entityId: courseId,
|
|
577
|
+
limit: 20
|
|
578
|
+
});
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
---
|
|
582
|
+
|
|
583
|
+
#### `countByType`
|
|
584
|
+
Count entities by type in a group.
|
|
585
|
+
|
|
586
|
+
**Arguments:**
|
|
587
|
+
```typescript
|
|
588
|
+
{
|
|
589
|
+
groupId: Id<"groups">
|
|
590
|
+
}
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
**Returns:** `Record<string, number>`
|
|
594
|
+
|
|
595
|
+
**Example:**
|
|
596
|
+
```typescript
|
|
597
|
+
const counts = await convex.query(api.queries.entities.countByType, {
|
|
598
|
+
groupId: acmeCorpId
|
|
599
|
+
});
|
|
600
|
+
// Returns: { user: 50, course: 12, lesson: 150, project: 8 }
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
**Use Case:** Dashboard statistics
|
|
604
|
+
|
|
605
|
+
---
|
|
606
|
+
|
|
607
|
+
#### `countByStatus`
|
|
608
|
+
Count entities by status in a group.
|
|
609
|
+
|
|
610
|
+
**Arguments:**
|
|
611
|
+
```typescript
|
|
612
|
+
{
|
|
613
|
+
groupId: Id<"groups">,
|
|
614
|
+
type?: string
|
|
615
|
+
}
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
**Returns:** `Record<string, number>`
|
|
619
|
+
|
|
620
|
+
**Example:**
|
|
621
|
+
```typescript
|
|
622
|
+
const statuses = await convex.query(api.queries.entities.countByStatus, {
|
|
623
|
+
groupId: acmeCorpId,
|
|
624
|
+
type: "course"
|
|
625
|
+
});
|
|
626
|
+
// Returns: { draft: 3, published: 8, archived: 1 }
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
**Use Case:** Workflow dashboards
|
|
630
|
+
|
|
631
|
+
---
|
|
632
|
+
|
|
633
|
+
#### `getRecent`
|
|
634
|
+
Get recently created entities.
|
|
635
|
+
|
|
636
|
+
**Arguments:**
|
|
637
|
+
```typescript
|
|
638
|
+
{
|
|
639
|
+
groupId: Id<"groups">,
|
|
640
|
+
type?: string,
|
|
641
|
+
limit?: number
|
|
642
|
+
}
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
**Returns:** `Entity[]` (sorted by createdAt, most recent first)
|
|
646
|
+
|
|
647
|
+
**Example:**
|
|
648
|
+
```typescript
|
|
649
|
+
const recent = await convex.query(api.queries.entities.getRecent, {
|
|
650
|
+
groupId: acmeCorpId,
|
|
651
|
+
type: "project",
|
|
652
|
+
limit: 5
|
|
653
|
+
});
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
---
|
|
657
|
+
|
|
658
|
+
#### `getRecentlyUpdated`
|
|
659
|
+
Get recently updated entities.
|
|
660
|
+
|
|
661
|
+
**Arguments:**
|
|
662
|
+
```typescript
|
|
663
|
+
{
|
|
664
|
+
groupId: Id<"groups">,
|
|
665
|
+
type?: string,
|
|
666
|
+
limit?: number
|
|
667
|
+
}
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
**Returns:** `Entity[]` (sorted by updatedAt, most recent first)
|
|
671
|
+
|
|
672
|
+
**Example:**
|
|
673
|
+
```typescript
|
|
674
|
+
const updated = await convex.query(api.queries.entities.getRecentlyUpdated, {
|
|
675
|
+
groupId: acmeCorpId,
|
|
676
|
+
limit: 10
|
|
677
|
+
});
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
---
|
|
681
|
+
|
|
682
|
+
### Mutations
|
|
683
|
+
|
|
684
|
+
#### `create`
|
|
685
|
+
Create a new entity.
|
|
686
|
+
|
|
687
|
+
**Arguments:**
|
|
688
|
+
```typescript
|
|
689
|
+
{
|
|
690
|
+
groupId: Id<"groups">,
|
|
691
|
+
type: string, // Must be valid ThingType from ontology
|
|
692
|
+
name: string,
|
|
693
|
+
properties?: any, // Type-specific metadata
|
|
694
|
+
status?: "draft" | "active" | "published" | "archived" | "inactive"
|
|
695
|
+
}
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
**Returns:** `Id<"entities">`
|
|
699
|
+
|
|
700
|
+
**Example:**
|
|
701
|
+
```typescript
|
|
702
|
+
const courseId = await convex.mutation(api.mutations.entities.create, {
|
|
703
|
+
groupId: acmeCorpId,
|
|
704
|
+
type: "course",
|
|
705
|
+
name: "TypeScript Fundamentals",
|
|
706
|
+
properties: {
|
|
707
|
+
description: "Learn TypeScript from scratch",
|
|
708
|
+
duration: 40,
|
|
709
|
+
instructor: "Jane Doe",
|
|
710
|
+
price: 99
|
|
711
|
+
},
|
|
712
|
+
status: "draft"
|
|
713
|
+
});
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
**Validation:**
|
|
717
|
+
- Authenticates user
|
|
718
|
+
- Validates group exists and is active
|
|
719
|
+
- Validates type against THING_TYPES from ontology composition
|
|
720
|
+
- Logs `thing_created` event
|
|
721
|
+
|
|
722
|
+
---
|
|
723
|
+
|
|
724
|
+
#### `update`
|
|
725
|
+
Update an existing entity.
|
|
726
|
+
|
|
727
|
+
**Arguments:**
|
|
728
|
+
```typescript
|
|
729
|
+
{
|
|
730
|
+
entityId: Id<"entities">,
|
|
731
|
+
name?: string,
|
|
732
|
+
properties?: any,
|
|
733
|
+
status?: "draft" | "active" | "published" | "archived" | "inactive"
|
|
734
|
+
}
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
**Returns:** `Id<"entities">`
|
|
738
|
+
|
|
739
|
+
**Example:**
|
|
740
|
+
```typescript
|
|
741
|
+
await convex.mutation(api.mutations.entities.update, {
|
|
742
|
+
entityId: courseId,
|
|
743
|
+
status: "published",
|
|
744
|
+
properties: {
|
|
745
|
+
publishedAt: Date.now()
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
**Audit Trail:** Logs changes in `thing_updated` event metadata
|
|
751
|
+
|
|
752
|
+
---
|
|
753
|
+
|
|
754
|
+
#### `archive`
|
|
755
|
+
Archive an entity (soft delete).
|
|
756
|
+
|
|
757
|
+
**Arguments:**
|
|
758
|
+
```typescript
|
|
759
|
+
{
|
|
760
|
+
entityId: Id<"entities">
|
|
761
|
+
}
|
|
762
|
+
```
|
|
763
|
+
|
|
764
|
+
**Returns:** `Id<"entities">`
|
|
765
|
+
|
|
766
|
+
**Example:**
|
|
767
|
+
```typescript
|
|
768
|
+
await convex.mutation(api.mutations.entities.archive, {
|
|
769
|
+
entityId: oldCourseId
|
|
770
|
+
});
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
**Behavior:**
|
|
774
|
+
- Sets status to "archived"
|
|
775
|
+
- Sets deletedAt timestamp
|
|
776
|
+
- Maintains audit trail
|
|
777
|
+
- Does NOT delete data
|
|
778
|
+
|
|
779
|
+
---
|
|
780
|
+
|
|
781
|
+
#### `restore`
|
|
782
|
+
Restore an archived entity.
|
|
783
|
+
|
|
784
|
+
**Arguments:**
|
|
785
|
+
```typescript
|
|
786
|
+
{
|
|
787
|
+
entityId: Id<"entities">
|
|
788
|
+
}
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
**Returns:** `Id<"entities">`
|
|
792
|
+
|
|
793
|
+
**Example:**
|
|
794
|
+
```typescript
|
|
795
|
+
await convex.mutation(api.mutations.entities.restore, {
|
|
796
|
+
entityId: oldCourseId
|
|
797
|
+
});
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
**Behavior:**
|
|
801
|
+
- Sets status to "active"
|
|
802
|
+
- Clears deletedAt timestamp
|
|
803
|
+
- Logs `thing_created` event with action: "restored"
|
|
804
|
+
|
|
805
|
+
---
|
|
806
|
+
|
|
807
|
+
## Entity Types (Ontology Composition)
|
|
808
|
+
|
|
809
|
+
**Available via:** `THING_TYPES` constant from ontology composition
|
|
810
|
+
|
|
811
|
+
**Dynamic Generation:** Types auto-generated from YAML ontologies based on enabled features.
|
|
812
|
+
|
|
813
|
+
**Current Features:** blog, portfolio, courses, tokens, agents, etc.
|
|
814
|
+
|
|
815
|
+
**Example Types:**
|
|
816
|
+
- `user` - Platform user
|
|
817
|
+
- `course` - Educational course
|
|
818
|
+
- `lesson` - Course lesson
|
|
819
|
+
- `project` - Portfolio project
|
|
820
|
+
- `blog_post` - Blog article
|
|
821
|
+
- `token` - Digital token/asset
|
|
822
|
+
- `agent` - AI agent
|
|
823
|
+
- `skill` - User skill
|
|
824
|
+
- `award` - Achievement
|
|
825
|
+
|
|
826
|
+
**Validation:** All entity creation validates type against current THING_TYPES.
|
|
827
|
+
|
|
828
|
+
---
|
|
829
|
+
|
|
830
|
+
## Error Handling
|
|
831
|
+
|
|
832
|
+
### Common Errors
|
|
833
|
+
|
|
834
|
+
#### Authentication Errors
|
|
835
|
+
```typescript
|
|
836
|
+
{
|
|
837
|
+
error: {
|
|
838
|
+
code: "UNAUTHENTICATED",
|
|
839
|
+
message: "Must be logged in to create entities"
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
#### Validation Errors
|
|
845
|
+
```typescript
|
|
846
|
+
{
|
|
847
|
+
error: {
|
|
848
|
+
code: "INVALID_TYPE",
|
|
849
|
+
message: "Invalid entity type \"foo\". Must be one of: user, course, ..."
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
```
|
|
853
|
+
|
|
854
|
+
#### Permission Errors
|
|
855
|
+
```typescript
|
|
856
|
+
{
|
|
857
|
+
error: {
|
|
858
|
+
code: "GROUP_ACCESS_DENIED",
|
|
859
|
+
message: "Entity not found in specified group"
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
```
|
|
863
|
+
|
|
864
|
+
#### Not Found Errors
|
|
865
|
+
```typescript
|
|
866
|
+
{
|
|
867
|
+
error: {
|
|
868
|
+
code: "NOT_FOUND",
|
|
869
|
+
message: "Group not found"
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
```
|
|
873
|
+
|
|
874
|
+
---
|
|
875
|
+
|
|
876
|
+
## Rate Limiting
|
|
877
|
+
|
|
878
|
+
**Per-User Limits:**
|
|
879
|
+
- Queries: 1000/minute
|
|
880
|
+
- Mutations: 100/minute
|
|
881
|
+
|
|
882
|
+
**Per-Organization Limits (by plan):**
|
|
883
|
+
- Starter: 10,000 API calls/month
|
|
884
|
+
- Pro: 100,000 API calls/month
|
|
885
|
+
- Enterprise: 1,000,000 API calls/month
|
|
886
|
+
|
|
887
|
+
**Response Headers:**
|
|
888
|
+
```
|
|
889
|
+
X-RateLimit-Limit: 1000
|
|
890
|
+
X-RateLimit-Remaining: 950
|
|
891
|
+
X-RateLimit-Reset: 1622547600
|
|
892
|
+
```
|
|
893
|
+
|
|
894
|
+
---
|
|
895
|
+
|
|
896
|
+
## Pagination
|
|
897
|
+
|
|
898
|
+
**Cursor-Based Pagination:**
|
|
899
|
+
```typescript
|
|
900
|
+
const results = await convex.query(api.queries.entities.list, {
|
|
901
|
+
groupId,
|
|
902
|
+
limit: 20,
|
|
903
|
+
cursor: "last_entity_id"
|
|
904
|
+
});
|
|
905
|
+
```
|
|
906
|
+
|
|
907
|
+
**Response:**
|
|
908
|
+
```typescript
|
|
909
|
+
{
|
|
910
|
+
items: Entity[],
|
|
911
|
+
nextCursor: string | null,
|
|
912
|
+
hasMore: boolean
|
|
913
|
+
}
|
|
914
|
+
```
|
|
915
|
+
|
|
916
|
+
---
|
|
917
|
+
|
|
918
|
+
## Connections API (Dimension 4)
|
|
919
|
+
|
|
920
|
+
See `/one/connections/connections.md` for complete Connections API documentation.
|
|
921
|
+
|
|
922
|
+
---
|
|
923
|
+
|
|
924
|
+
## Events API (Dimension 5)
|
|
925
|
+
|
|
926
|
+
See `/one/connections/events.md` for complete Events API documentation.
|
|
927
|
+
|
|
928
|
+
---
|
|
929
|
+
|
|
930
|
+
## Knowledge API (Dimension 6)
|
|
931
|
+
|
|
932
|
+
See `/one/connections/knowledge.md` for complete Knowledge API documentation including RAG and semantic search.
|
|
933
|
+
|
|
934
|
+
---
|
|
935
|
+
|
|
936
|
+
## Best Practices
|
|
937
|
+
|
|
938
|
+
### 1. Always Scope to Group
|
|
939
|
+
```typescript
|
|
940
|
+
// ✅ CORRECT
|
|
941
|
+
const entities = await convex.query(api.queries.entities.list, {
|
|
942
|
+
groupId: acmeCorpId,
|
|
943
|
+
type: "course"
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
// ❌ WRONG - Missing groupId (breaks multi-tenancy)
|
|
947
|
+
const entities = await convex.query(api.queries.entities.listAll);
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
### 2. Validate Group Access
|
|
951
|
+
```typescript
|
|
952
|
+
// ✅ CORRECT - Validate entity belongs to expected group
|
|
953
|
+
const entity = await convex.query(api.queries.entities.getById, {
|
|
954
|
+
entityId,
|
|
955
|
+
groupId: currentUserGroupId
|
|
956
|
+
});
|
|
957
|
+
```
|
|
958
|
+
|
|
959
|
+
### 3. Use Indexes for Performance
|
|
960
|
+
```typescript
|
|
961
|
+
// ✅ CORRECT - Uses group_type index
|
|
962
|
+
const courses = await convex.query(api.queries.entities.list, {
|
|
963
|
+
groupId,
|
|
964
|
+
type: "course"
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
// ❌ SLOW - No index, filters in memory
|
|
968
|
+
const courses = (await convex.query(api.queries.entities.list, { groupId }))
|
|
969
|
+
.filter(e => e.type === "course");
|
|
970
|
+
```
|
|
971
|
+
|
|
972
|
+
### 4. Log All Mutations
|
|
973
|
+
```typescript
|
|
974
|
+
// ✅ Automatically logged by mutations
|
|
975
|
+
await convex.mutation(api.mutations.entities.create, { /* ... */ });
|
|
976
|
+
// Creates thing_created event
|
|
977
|
+
|
|
978
|
+
// Event includes:
|
|
979
|
+
// - actorId (who did it)
|
|
980
|
+
// - targetId (what was created)
|
|
981
|
+
// - timestamp (when)
|
|
982
|
+
// - metadata (details)
|
|
983
|
+
```
|
|
984
|
+
|
|
985
|
+
### 5. Handle Errors Gracefully
|
|
986
|
+
```typescript
|
|
987
|
+
try {
|
|
988
|
+
const entity = await convex.query(api.queries.entities.getById, { entityId });
|
|
989
|
+
} catch (error) {
|
|
990
|
+
if (error.code === "NOT_FOUND") {
|
|
991
|
+
// Handle missing entity
|
|
992
|
+
} else if (error.code === "UNAUTHENTICATED") {
|
|
993
|
+
// Redirect to login
|
|
994
|
+
} else {
|
|
995
|
+
// Log unexpected error
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
```
|
|
999
|
+
|
|
1000
|
+
---
|
|
1001
|
+
|
|
1002
|
+
## Related Documentation
|
|
1003
|
+
|
|
1004
|
+
- [Architecture Overview](/one/knowledge/architecture.md)
|
|
1005
|
+
- [Ontology Specification](/one/knowledge/ontology.md)
|
|
1006
|
+
- [Integration Guide](/one/connections/integration-guide.md)
|
|
1007
|
+
- [Multi-Tenant Best Practices](/one/connections/multi-tenant.md)
|
|
1008
|
+
|
|
1009
|
+
---
|
|
1010
|
+
|
|
1011
|
+
**Built with clarity and infinite scale in mind.**
|