oneie 3.6.7 → 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/one.md +198 -116
- package/.claude/commands/plan.md +394 -80
- package/.claude/commands/release.md +41 -19
- package/.claude/commands/server.md +2 -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,478 @@
|
|
|
1
|
+
# Effect.ts DataProvider Pattern Guide
|
|
2
|
+
|
|
3
|
+
## Quick Reference
|
|
4
|
+
|
|
5
|
+
The DataProvider interface returns **Effect.ts wrapped values**. Always extract them with `Effect.runPromise()` before using.
|
|
6
|
+
|
|
7
|
+
## Pattern Checklist
|
|
8
|
+
|
|
9
|
+
- [ ] Import Effect at top: `const { Effect } = await import('effect');`
|
|
10
|
+
- [ ] Wrap all DataProvider calls: `await Effect.runPromise(provider.*.*())`
|
|
11
|
+
- [ ] Use correct property names from DataProvider interface
|
|
12
|
+
- [ ] Handle create() methods (return ID string)
|
|
13
|
+
- [ ] Handle list() methods (return arrays)
|
|
14
|
+
- [ ] Handle get() methods (return single entity or throw error)
|
|
15
|
+
- [ ] Handle update() methods (return void)
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Common Patterns
|
|
20
|
+
|
|
21
|
+
### Pattern 1: List with Pagination
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// WRONG - connections is an Effect, not an array
|
|
25
|
+
let connections = await provider.connections.list(filter);
|
|
26
|
+
const paginated = connections.slice(offset, offset + limit); // ERROR!
|
|
27
|
+
|
|
28
|
+
// CORRECT - extract with Effect.runPromise()
|
|
29
|
+
const { Effect } = await import('effect');
|
|
30
|
+
let connections = await Effect.runPromise(provider.connections.list(filter));
|
|
31
|
+
const paginated = connections.slice(offset, offset + limit); // Works!
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Pattern 2: Get Single Entity
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
// WRONG
|
|
38
|
+
const thing = await provider.things.get(id);
|
|
39
|
+
if (!thing) { /* ... */ } // thing is Effect, not Thing
|
|
40
|
+
|
|
41
|
+
// CORRECT
|
|
42
|
+
const { Effect } = await import('effect');
|
|
43
|
+
const thing = await Effect.runPromise(provider.things.get(id));
|
|
44
|
+
if (!thing) { /* ... */ } // thing is now Thing or throws error
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Pattern 3: Create Entity
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
// WRONG
|
|
51
|
+
const thing = await provider.things.create(input);
|
|
52
|
+
return JSON.stringify(successResponse(thing)); // thing is string (ID), not object!
|
|
53
|
+
|
|
54
|
+
// CORRECT
|
|
55
|
+
const { Effect } = await import('effect');
|
|
56
|
+
const thingId = await Effect.runPromise(provider.things.create(input));
|
|
57
|
+
return JSON.stringify(successResponse({ _id: thingId })); // Correct object
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Pattern 4: Update Entity
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
// WRONG
|
|
64
|
+
const updated = await provider.things.update(id, input);
|
|
65
|
+
return JSON.stringify(successResponse(updated)); // updated is void!
|
|
66
|
+
|
|
67
|
+
// CORRECT
|
|
68
|
+
const { Effect } = await import('effect');
|
|
69
|
+
await Effect.runPromise(provider.things.update(id, input));
|
|
70
|
+
return JSON.stringify(successResponse({ _id: id, ...input })); // Return reconstructed object
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Pattern 5: Filter and Sort
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
// WRONG
|
|
77
|
+
let events = await provider.events.list(filter);
|
|
78
|
+
events.sort((a, b) => a.timestamp - b.timestamp); // ERROR: sort on Effect
|
|
79
|
+
const paginated = events.slice(offset, offset + limit); // ERROR: slice on Effect
|
|
80
|
+
|
|
81
|
+
// CORRECT
|
|
82
|
+
const { Effect } = await import('effect');
|
|
83
|
+
let events = await Effect.runPromise(provider.events.list(filter));
|
|
84
|
+
events.sort((a, b) => a.timestamp - b.timestamp); // Works: array method
|
|
85
|
+
const paginated = events.slice(offset, offset + limit); // Works: array method
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## DataProvider Interface Mapping
|
|
91
|
+
|
|
92
|
+
### things
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
// List things with filters
|
|
96
|
+
const things = await Effect.runPromise(
|
|
97
|
+
provider.things.list({
|
|
98
|
+
type?: string;
|
|
99
|
+
status?: ThingStatus;
|
|
100
|
+
groupId?: string;
|
|
101
|
+
limit?: number;
|
|
102
|
+
offset?: number;
|
|
103
|
+
})
|
|
104
|
+
); // Returns: Thing[]
|
|
105
|
+
|
|
106
|
+
// Get single thing
|
|
107
|
+
const thing = await Effect.runPromise(
|
|
108
|
+
provider.things.get(id)
|
|
109
|
+
); // Returns: Thing | throws ThingNotFoundError
|
|
110
|
+
|
|
111
|
+
// Create thing
|
|
112
|
+
const thingId = await Effect.runPromise(
|
|
113
|
+
provider.things.create({
|
|
114
|
+
type: string;
|
|
115
|
+
name: string;
|
|
116
|
+
groupId: string;
|
|
117
|
+
properties?: Record<string, any>;
|
|
118
|
+
status?: ThingStatus;
|
|
119
|
+
})
|
|
120
|
+
); // Returns: string (the _id)
|
|
121
|
+
|
|
122
|
+
// Update thing
|
|
123
|
+
await Effect.runPromise(
|
|
124
|
+
provider.things.update(id, {
|
|
125
|
+
name?: string;
|
|
126
|
+
properties?: Record<string, any>;
|
|
127
|
+
status?: ThingStatus;
|
|
128
|
+
})
|
|
129
|
+
); // Returns: void
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### connections
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
// List connections
|
|
136
|
+
const connections = await Effect.runPromise(
|
|
137
|
+
provider.connections.list({
|
|
138
|
+
fromEntityId?: string; // NOT fromThingId
|
|
139
|
+
toEntityId?: string; // NOT toThingId
|
|
140
|
+
relationshipType?: ConnectionType;
|
|
141
|
+
limit?: number;
|
|
142
|
+
offset?: number;
|
|
143
|
+
})
|
|
144
|
+
); // Returns: Connection[]
|
|
145
|
+
|
|
146
|
+
// Create connection
|
|
147
|
+
const connectionId = await Effect.runPromise(
|
|
148
|
+
provider.connections.create({
|
|
149
|
+
fromEntityId: string; // NOT fromThingId
|
|
150
|
+
toEntityId: string; // NOT toThingId
|
|
151
|
+
relationshipType: ConnectionType;
|
|
152
|
+
groupId: string;
|
|
153
|
+
metadata?: Record<string, any>;
|
|
154
|
+
})
|
|
155
|
+
); // Returns: string (the _id)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### events
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
// List events
|
|
162
|
+
const events = await Effect.runPromise(
|
|
163
|
+
provider.events.list({
|
|
164
|
+
type?: string;
|
|
165
|
+
actorId?: string;
|
|
166
|
+
targetId?: string;
|
|
167
|
+
since?: number; // NOT startTime
|
|
168
|
+
until?: number; // NOT endTime
|
|
169
|
+
limit?: number;
|
|
170
|
+
offset?: number;
|
|
171
|
+
})
|
|
172
|
+
); // Returns: Event[]
|
|
173
|
+
|
|
174
|
+
// Create event
|
|
175
|
+
const eventId = await Effect.runPromise(
|
|
176
|
+
provider.events.create({ // NOT .record()
|
|
177
|
+
type: string;
|
|
178
|
+
actorId: string;
|
|
179
|
+
targetId?: string;
|
|
180
|
+
groupId: string;
|
|
181
|
+
metadata?: Record<string, any>;
|
|
182
|
+
})
|
|
183
|
+
); // Returns: string (the _id)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### knowledge
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
// List knowledge
|
|
190
|
+
const knowledge = await Effect.runPromise(
|
|
191
|
+
provider.knowledge.list({
|
|
192
|
+
query?: string;
|
|
193
|
+
knowledgeType?: KnowledgeType;
|
|
194
|
+
limit?: number;
|
|
195
|
+
})
|
|
196
|
+
); // Returns: Knowledge[]
|
|
197
|
+
|
|
198
|
+
// Search with embedding
|
|
199
|
+
const results = await Effect.runPromise(
|
|
200
|
+
provider.knowledge.search(
|
|
201
|
+
embedding, // number[] (from OpenAI, etc.)
|
|
202
|
+
{
|
|
203
|
+
sourceThingId?: string;
|
|
204
|
+
knowledgeType?: KnowledgeType;
|
|
205
|
+
limit?: number;
|
|
206
|
+
}
|
|
207
|
+
)
|
|
208
|
+
); // Returns: Knowledge[]
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### auth
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
// Get current user
|
|
215
|
+
const user = await Effect.runPromise(
|
|
216
|
+
provider.auth.getCurrentUser()
|
|
217
|
+
); // Returns: User | null
|
|
218
|
+
|
|
219
|
+
// Login
|
|
220
|
+
const result = await Effect.runPromise(
|
|
221
|
+
provider.auth.login({
|
|
222
|
+
email: string;
|
|
223
|
+
password: string;
|
|
224
|
+
})
|
|
225
|
+
); // Returns: AuthResult
|
|
226
|
+
|
|
227
|
+
// Signup
|
|
228
|
+
const result = await Effect.runPromise(
|
|
229
|
+
provider.auth.signup({
|
|
230
|
+
email: string;
|
|
231
|
+
password: string;
|
|
232
|
+
name?: string;
|
|
233
|
+
})
|
|
234
|
+
); // Returns: AuthResult
|
|
235
|
+
|
|
236
|
+
// Magic link
|
|
237
|
+
const result = await Effect.runPromise(
|
|
238
|
+
provider.auth.magicLinkAuth({
|
|
239
|
+
token: string;
|
|
240
|
+
})
|
|
241
|
+
); // Returns: AuthResult
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Common Mistakes to Avoid
|
|
247
|
+
|
|
248
|
+
### Mistake 1: Forgetting Effect.runPromise()
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
// WRONG
|
|
252
|
+
const connections = await provider.connections.list(filter);
|
|
253
|
+
connections.slice(0, 10); // Error: Effect has no slice method
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**Fix**: Use Effect.runPromise()
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
const connections = await Effect.runPromise(provider.connections.list(filter));
|
|
260
|
+
connections.slice(0, 10); // Works!
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
### Mistake 2: Wrong Property Names
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
// WRONG - DataProvider uses entityId, not thingId
|
|
269
|
+
const connections = await provider.connections.list({
|
|
270
|
+
fromThingId: id, // Error: property doesn't exist
|
|
271
|
+
toThingId: id, // Error: property doesn't exist
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// CORRECT
|
|
275
|
+
const connections = await Effect.runPromise(
|
|
276
|
+
provider.connections.list({
|
|
277
|
+
fromEntityId: id,
|
|
278
|
+
toEntityId: id,
|
|
279
|
+
})
|
|
280
|
+
);
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
### Mistake 3: Using .record() Instead of .create()
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
// WRONG - events don't have .record()
|
|
289
|
+
const eventId = await Effect.runPromise(
|
|
290
|
+
provider.events.record({ ... }) // Error: method doesn't exist
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
// CORRECT
|
|
294
|
+
const eventId = await Effect.runPromise(
|
|
295
|
+
provider.events.create({ ... })
|
|
296
|
+
);
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
### Mistake 4: Using provider.people Instead of provider.things or provider.auth
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
// WRONG - DataProvider doesn't have .people property
|
|
305
|
+
const person = await provider.people.get(id);
|
|
306
|
+
const user = await provider.people.current();
|
|
307
|
+
|
|
308
|
+
// CORRECT - People are Things with type: 'creator'
|
|
309
|
+
const person = await Effect.runPromise(provider.things.get(id));
|
|
310
|
+
|
|
311
|
+
// CORRECT - Current user is from auth
|
|
312
|
+
const user = await Effect.runPromise(provider.auth.getCurrentUser());
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
### Mistake 5: Returning Wrong Type from create()
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
// WRONG - create() returns string (ID), not the entity
|
|
321
|
+
const thing = await Effect.runPromise(provider.things.create(input));
|
|
322
|
+
return JSON.stringify(successResponse(thing)); // thing is "123", not an object
|
|
323
|
+
|
|
324
|
+
// CORRECT
|
|
325
|
+
const thingId = await Effect.runPromise(provider.things.create(input));
|
|
326
|
+
return JSON.stringify(successResponse({ _id: thingId }));
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
### Mistake 6: Trying to Use Array Methods on Effect
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
// WRONG
|
|
335
|
+
let things = await provider.things.list();
|
|
336
|
+
things.sort((a, b) => a.name.localeCompare(b.name)); // Error: Effect has no sort
|
|
337
|
+
things.filter(t => t.type === 'course'); // Error: Effect has no filter
|
|
338
|
+
|
|
339
|
+
// CORRECT
|
|
340
|
+
let things = await Effect.runPromise(provider.things.list());
|
|
341
|
+
things.sort((a, b) => a.name.localeCompare(b.name)); // Works
|
|
342
|
+
things.filter(t => t.type === 'course'); // Works
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## Debugging Tips
|
|
348
|
+
|
|
349
|
+
### If you see: "Property does not exist on Effect"
|
|
350
|
+
|
|
351
|
+
You forgot `Effect.runPromise()`
|
|
352
|
+
|
|
353
|
+
```typescript
|
|
354
|
+
// Add this:
|
|
355
|
+
const { Effect } = await import('effect');
|
|
356
|
+
const result = await Effect.runPromise(provider.things.list());
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### If you see: "Method not found on DataProvider"
|
|
360
|
+
|
|
361
|
+
Check the exact method name in the DataProvider interface:
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
// provider.events.record is WRONG
|
|
365
|
+
provider.events.create // CORRECT
|
|
366
|
+
|
|
367
|
+
// provider.people.get is WRONG
|
|
368
|
+
provider.things.get // CORRECT for getting a person (type: 'creator')
|
|
369
|
+
provider.auth.getCurrentUser() // CORRECT for current user
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### If you see: "Type is string but expected Thing"
|
|
373
|
+
|
|
374
|
+
The create methods return IDs, not entities:
|
|
375
|
+
|
|
376
|
+
```typescript
|
|
377
|
+
// WRONG - thingId is string, not Thing
|
|
378
|
+
const thing = await Effect.runPromise(provider.things.create(input));
|
|
379
|
+
const type: Thing = thing; // Error!
|
|
380
|
+
|
|
381
|
+
// CORRECT
|
|
382
|
+
const thingId = await Effect.runPromise(provider.things.create(input));
|
|
383
|
+
const id: string = thingId; // Correct!
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
## Performance Considerations
|
|
389
|
+
|
|
390
|
+
### Avoid N+1 Queries
|
|
391
|
+
|
|
392
|
+
```typescript
|
|
393
|
+
// BAD - makes multiple Effect.runPromise calls
|
|
394
|
+
for (const thingId of thingIds) {
|
|
395
|
+
const thing = await Effect.runPromise(provider.things.get(thingId));
|
|
396
|
+
// process thing
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// BETTER - batch if possible, or accept sequential calls
|
|
400
|
+
const things = await Effect.runPromise(
|
|
401
|
+
provider.things.list({ type: 'course' })
|
|
402
|
+
);
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### Pagination is Built-In
|
|
406
|
+
|
|
407
|
+
```typescript
|
|
408
|
+
// Use limit/offset in the query to avoid fetching all
|
|
409
|
+
const things = await Effect.runPromise(
|
|
410
|
+
provider.things.list({
|
|
411
|
+
type: 'course',
|
|
412
|
+
limit: 50,
|
|
413
|
+
offset: 0,
|
|
414
|
+
})
|
|
415
|
+
);
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
## Complete Example: API Route
|
|
421
|
+
|
|
422
|
+
```typescript
|
|
423
|
+
import type { APIRoute } from 'astro';
|
|
424
|
+
import { getDefaultProvider } from '@/providers/factory';
|
|
425
|
+
import { successResponse, errorResponse, getStatusCode } from '../response';
|
|
426
|
+
|
|
427
|
+
export const GET: APIRoute = async ({ url }) => {
|
|
428
|
+
try {
|
|
429
|
+
const provider = getDefaultProvider();
|
|
430
|
+
const { Effect } = await import('effect');
|
|
431
|
+
|
|
432
|
+
// Parse query parameters
|
|
433
|
+
const type = url.searchParams.get('type');
|
|
434
|
+
const limit = Math.min(parseInt(url.searchParams.get('limit') || '50'), 1000);
|
|
435
|
+
const offset = parseInt(url.searchParams.get('offset') || '0');
|
|
436
|
+
|
|
437
|
+
// Build filter (use correct property names)
|
|
438
|
+
const filter: Record<string, any> = {};
|
|
439
|
+
if (type) filter.type = type;
|
|
440
|
+
|
|
441
|
+
// Extract Effect value
|
|
442
|
+
let things = await Effect.runPromise(provider.things.list(filter));
|
|
443
|
+
|
|
444
|
+
// Now use array methods
|
|
445
|
+
things = things.sort((a, b) => a.name.localeCompare(b.name));
|
|
446
|
+
const paginated = things.slice(offset, offset + limit);
|
|
447
|
+
|
|
448
|
+
return new Response(
|
|
449
|
+
JSON.stringify(
|
|
450
|
+
successResponse({
|
|
451
|
+
things: paginated,
|
|
452
|
+
total: things.length,
|
|
453
|
+
limit,
|
|
454
|
+
offset,
|
|
455
|
+
})
|
|
456
|
+
),
|
|
457
|
+
{ status: 200 }
|
|
458
|
+
);
|
|
459
|
+
} catch (error) {
|
|
460
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
461
|
+
return new Response(JSON.stringify(errorResponse('INTERNAL_ERROR', message)), {
|
|
462
|
+
status: 500,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
---
|
|
469
|
+
|
|
470
|
+
## Summary
|
|
471
|
+
|
|
472
|
+
1. **Always import Effect**: `const { Effect } = await import('effect');`
|
|
473
|
+
2. **Always extract values**: `await Effect.runPromise(provider.*.*())`
|
|
474
|
+
3. **Use correct names**: fromEntityId, toEntityId, since, until, create (not record)
|
|
475
|
+
4. **Know return types**: create() → string, list() → array, get() → entity or error, update() → void
|
|
476
|
+
5. **Test with curl**: Verify endpoints work before shipping
|
|
477
|
+
|
|
478
|
+
All 7 API route files have been updated with these patterns. TypeScript check passes.
|