oneie 3.6.27 → 3.6.30

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.
@@ -11,12 +11,12 @@ version: 1.0.0
11
11
  ai_context: |
12
12
  This document is part of the knowledge dimension in the ontology-cheatsheet.md category.
13
13
  Location: one/knowledge/ontology-cheatsheet.md
14
- Purpose: Documents multi-ontology architecture cheat sheet
14
+ Purpose: Documents ONE Ontology architecture cheat sheet
15
15
  Related dimensions: connections, events, people, things
16
16
  For AI agents: Read this to understand ontology cheatsheet.
17
17
  ---
18
18
 
19
- # Multi-Ontology Architecture Cheat Sheet
19
+ # ONE Ontology Architecture Cheat Sheet
20
20
 
21
21
  **Quick Reference Guide** | **Version:** 1.0.0
22
22
 
@@ -104,8 +104,8 @@ thingTypes:
104
104
  slug: string
105
105
 
106
106
  # Status and metadata
107
- status: string # active, inactive, draft
108
- createdBy: string # User ID
107
+ status: string # active, inactive, draft
108
+ createdBy: string # User ID
109
109
 
110
110
  # Feature-specific fields
111
111
  customField1: string
@@ -135,7 +135,7 @@ thingTypes:
135
135
  connectionTypes:
136
136
  - name: owns_entity
137
137
  description: "Creator owns entity"
138
- fromType: creator # From core
138
+ fromType: creator # From core
139
139
  toType: my_entity
140
140
  metadata:
141
141
  role: string
@@ -151,7 +151,7 @@ connectionTypes:
151
151
  - name: related_to
152
152
  description: "Generic relationship"
153
153
  fromType: my_entity
154
- toType: my_entity # Self-referential
154
+ toType: my_entity # Self-referential
155
155
  metadata:
156
156
  relationshipType: string
157
157
 
@@ -195,51 +195,51 @@ eventTypes:
195
195
  ### 1. Create Entity with Ownership
196
196
 
197
197
  ```typescript
198
- import { mutation } from '../_generated/server';
199
- import { v } from 'convex/values';
200
- import type { ThingType, ConnectionType, EventType } from '../types/ontology';
198
+ import { mutation } from "../_generated/server";
199
+ import { v } from "convex/values";
200
+ import type { ThingType, ConnectionType, EventType } from "../types/ontology";
201
201
 
202
202
  export const create = mutation({
203
203
  args: {
204
- groupId: v.id('groups'),
204
+ groupId: v.id("groups"),
205
205
  name: v.string(),
206
206
  properties: v.any(),
207
207
  },
208
208
  handler: async (ctx, args) => {
209
209
  const userId = await ctx.auth.getUserIdentity();
210
- if (!userId) throw new Error('Unauthorized');
210
+ if (!userId) throw new Error("Unauthorized");
211
211
 
212
212
  // 1. Create entity
213
- const entityId = await ctx.db.insert('entities', {
213
+ const entityId = await ctx.db.insert("entities", {
214
214
  groupId: args.groupId,
215
- type: 'my_entity' as ThingType,
215
+ type: "my_entity" as ThingType,
216
216
  name: args.name,
217
217
  properties: {
218
218
  ...args.properties,
219
219
  createdBy: userId.tokenIdentifier,
220
220
  },
221
- status: 'active',
221
+ status: "active",
222
222
  createdAt: Date.now(),
223
223
  updatedAt: Date.now(),
224
224
  });
225
225
 
226
226
  // 2. Create ownership connection
227
- await ctx.db.insert('connections', {
227
+ await ctx.db.insert("connections", {
228
228
  groupId: args.groupId,
229
229
  fromEntityId: userId.tokenIdentifier,
230
230
  toEntityId: entityId,
231
- relationshipType: 'owns' as ConnectionType,
231
+ relationshipType: "owns" as ConnectionType,
232
232
  metadata: {
233
- role: 'owner',
234
- permissions: ['read', 'write', 'delete'],
233
+ role: "owner",
234
+ permissions: ["read", "write", "delete"],
235
235
  },
236
236
  createdAt: Date.now(),
237
237
  });
238
238
 
239
239
  // 3. Log creation event
240
- await ctx.db.insert('events', {
240
+ await ctx.db.insert("events", {
241
241
  groupId: args.groupId,
242
- type: 'entity_created' as EventType,
242
+ type: "entity_created" as EventType,
243
243
  actorId: userId.tokenIdentifier,
244
244
  targetId: entityId,
245
245
  timestamp: Date.now(),
@@ -254,19 +254,19 @@ export const create = mutation({
254
254
  ### 2. Query Entities with Connections
255
255
 
256
256
  ```typescript
257
- import { query } from '../_generated/server';
258
- import { v } from 'convex/values';
257
+ import { query } from "../_generated/server";
258
+ import { v } from "convex/values";
259
259
 
260
260
  export const listWithOwners = query({
261
261
  args: {
262
- groupId: v.id('groups'),
262
+ groupId: v.id("groups"),
263
263
  },
264
264
  handler: async (ctx, args) => {
265
265
  // Get entities
266
266
  const entities = await ctx.db
267
- .query('entities')
268
- .withIndex('group_type', (q) =>
269
- q.eq('groupId', args.groupId).eq('type', 'my_entity')
267
+ .query("entities")
268
+ .withIndex("group_type", (q) =>
269
+ q.eq("groupId", args.groupId).eq("type", "my_entity")
270
270
  )
271
271
  .collect();
272
272
 
@@ -274,9 +274,9 @@ export const listWithOwners = query({
274
274
  const entitiesWithOwners = await Promise.all(
275
275
  entities.map(async (entity) => {
276
276
  const ownership = await ctx.db
277
- .query('connections')
278
- .withIndex('to_type', (q) =>
279
- q.eq('toEntityId', entity._id).eq('relationshipType', 'owns')
277
+ .query("connections")
278
+ .withIndex("to_type", (q) =>
279
+ q.eq("toEntityId", entity._id).eq("relationshipType", "owns")
280
280
  )
281
281
  .first();
282
282
 
@@ -300,7 +300,7 @@ export const listWithOwners = query({
300
300
  ### 3. Type Validation
301
301
 
302
302
  ```typescript
303
- import { isThingType, isConnectionType, isEventType } from '../types/ontology';
303
+ import { isThingType, isConnectionType, isEventType } from "../types/ontology";
304
304
 
305
305
  // Validate thing type
306
306
  export const validateEntity = mutation({
@@ -313,7 +313,7 @@ export const validateEntity = mutation({
313
313
  }
314
314
 
315
315
  // Now TypeScript knows args.type is valid
316
- const entity = await ctx.db.insert('entities', {
316
+ const entity = await ctx.db.insert("entities", {
317
317
  type: args.type as ThingType,
318
318
  // ...
319
319
  });
@@ -324,14 +324,14 @@ export const validateEntity = mutation({
324
324
  ### 4. Feature Detection
325
325
 
326
326
  ```typescript
327
- import { ONTOLOGY_METADATA } from '../types/ontology';
327
+ import { ONTOLOGY_METADATA } from "../types/ontology";
328
328
 
329
329
  export const getFeatures = query({
330
330
  handler: async () => {
331
331
  return {
332
332
  enabled: ONTOLOGY_METADATA.features,
333
- hasBlog: ONTOLOGY_METADATA.features.includes('blog'),
334
- hasShop: ONTOLOGY_METADATA.features.includes('shop'),
333
+ hasBlog: ONTOLOGY_METADATA.features.includes("blog"),
334
+ hasShop: ONTOLOGY_METADATA.features.includes("shop"),
335
335
  counts: {
336
336
  things: ONTOLOGY_METADATA.thingTypeCount,
337
337
  connections: ONTOLOGY_METADATA.connectionTypeCount,
@@ -346,8 +346,8 @@ export const createContent = mutation({
346
346
  handler: async (ctx, args) => {
347
347
  const features = ONTOLOGY_METADATA.features;
348
348
 
349
- if (args.type === 'blog_post' && !features.includes('blog')) {
350
- throw new Error('Blog feature not enabled');
349
+ if (args.type === "blog_post" && !features.includes("blog")) {
350
+ throw new Error("Blog feature not enabled");
351
351
  }
352
352
 
353
353
  // Create entity...
@@ -360,7 +360,7 @@ export const createContent = mutation({
360
360
  ```typescript
361
361
  export const batchCreate = mutation({
362
362
  args: {
363
- groupId: v.id('groups'),
363
+ groupId: v.id("groups"),
364
364
  entities: v.array(
365
365
  v.object({
366
366
  type: v.string(),
@@ -377,18 +377,18 @@ export const batchCreate = mutation({
377
377
  results.push({
378
378
  name: entity.name,
379
379
  success: false,
380
- error: 'Invalid type',
380
+ error: "Invalid type",
381
381
  });
382
382
  continue;
383
383
  }
384
384
 
385
385
  try {
386
- const id = await ctx.db.insert('entities', {
386
+ const id = await ctx.db.insert("entities", {
387
387
  groupId: args.groupId,
388
388
  type: entity.type as ThingType,
389
389
  name: entity.name,
390
390
  properties: entity.properties,
391
- status: 'active',
391
+ status: "active",
392
392
  createdAt: Date.now(),
393
393
  updatedAt: Date.now(),
394
394
  });
@@ -417,24 +417,27 @@ export const batchCreate = mutation({
417
417
  ```typescript
418
418
  export const getAnalytics = query({
419
419
  args: {
420
- entityId: v.id('entities'),
420
+ entityId: v.id("entities"),
421
421
  days: v.optional(v.number()),
422
422
  },
423
423
  handler: async (ctx, args) => {
424
424
  const since = Date.now() - (args.days || 30) * 24 * 60 * 60 * 1000;
425
425
 
426
426
  const events = await ctx.db
427
- .query('events')
428
- .withIndex('target_time', (q) =>
429
- q.eq('targetId', args.entityId).gte('timestamp', since)
427
+ .query("events")
428
+ .withIndex("target_time", (q) =>
429
+ q.eq("targetId", args.entityId).gte("timestamp", since)
430
430
  )
431
431
  .collect();
432
432
 
433
433
  // Group by event type
434
- const byType = events.reduce((acc, event) => {
435
- acc[event.type] = (acc[event.type] || 0) + 1;
436
- return acc;
437
- }, {} as Record<string, number>);
434
+ const byType = events.reduce(
435
+ (acc, event) => {
436
+ acc[event.type] = (acc[event.type] || 0) + 1;
437
+ return acc;
438
+ },
439
+ {} as Record<string, number>
440
+ );
438
441
 
439
442
  return {
440
443
  period: `${args.days || 30} days`,
@@ -459,49 +462,49 @@ export const getAnalytics = query({
459
462
  ```typescript
460
463
  // Auto-generated from ontologies
461
464
  import type {
462
- ThingType, // Union of all thing types
463
- ConnectionType, // Union of all connection types
464
- EventType, // Union of all event types
465
- } from './types/ontology';
465
+ ThingType, // Union of all thing types
466
+ ConnectionType, // Union of all connection types
467
+ EventType, // Union of all event types
468
+ } from "./types/ontology";
466
469
 
467
470
  // Type arrays
468
471
  import {
469
- THING_TYPES, // string[] of all thing types
470
- CONNECTION_TYPES, // string[] of all connection types
471
- EVENT_TYPES, // string[] of all event types
472
- } from './types/ontology';
472
+ THING_TYPES, // string[] of all thing types
473
+ CONNECTION_TYPES, // string[] of all connection types
474
+ EVENT_TYPES, // string[] of all event types
475
+ } from "./types/ontology";
473
476
 
474
477
  // Type guards
475
478
  import {
476
- isThingType, // (value: string) => boolean
477
- isConnectionType, // (value: string) => boolean
478
- isEventType, // (value: string) => boolean
479
- } from './types/ontology';
479
+ isThingType, // (value: string) => boolean
480
+ isConnectionType, // (value: string) => boolean
481
+ isEventType, // (value: string) => boolean
482
+ } from "./types/ontology";
480
483
 
481
484
  // Metadata
482
485
  import {
483
- ONTOLOGY_METADATA // { features, generatedAt, counts }
484
- } from './types/ontology';
486
+ ONTOLOGY_METADATA, // { features, generatedAt, counts }
487
+ } from "./types/ontology";
485
488
  ```
486
489
 
487
490
  ### Database Schema Types
488
491
 
489
492
  ```typescript
490
493
  // Convex auto-generated types
491
- import type { Doc, Id } from './_generated/dataModel';
494
+ import type { Doc, Id } from "./_generated/dataModel";
492
495
 
493
496
  // Entity document
494
- type Entity = Doc<'entities'>;
495
- type EntityId = Id<'entities'>;
497
+ type Entity = Doc<"entities">;
498
+ type EntityId = Id<"entities">;
496
499
 
497
500
  // Connection document
498
- type Connection = Doc<'connections'>;
501
+ type Connection = Doc<"connections">;
499
502
 
500
503
  // Event document
501
- type Event = Doc<'events'>;
504
+ type Event = Doc<"events">;
502
505
 
503
506
  // Group document
504
- type Group = Doc<'groups'>;
507
+ type Group = Doc<"groups">;
505
508
  ```
506
509
 
507
510
  ---
@@ -511,6 +514,7 @@ type Group = Doc<'groups'>;
511
514
  ### Issue: Types not generating
512
515
 
513
516
  **Solution:**
517
+
514
518
  ```bash
515
519
  # Check YAML syntax
516
520
  bun run backend/scripts/validate-ontology.ts
@@ -525,6 +529,7 @@ cat backend/convex/types/ontology.ts
525
529
  ### Issue: Invalid type errors
526
530
 
527
531
  **Solution:**
532
+
528
533
  ```typescript
529
534
  // Always use type guards
530
535
  if (!isThingType(args.type)) {
@@ -540,6 +545,7 @@ if (!THING_TYPES.includes(args.type)) {
540
545
  ### Issue: Circular dependencies
541
546
 
542
547
  **Solution:**
548
+
543
549
  ```yaml
544
550
  # Feature A
545
551
  feature: featureA
@@ -557,6 +563,7 @@ extends: featureA,featureB
557
563
  ### Issue: Missing core types
558
564
 
559
565
  **Solution:**
566
+
560
567
  ```yaml
561
568
  # Always extend core
562
569
  extends: core
@@ -564,13 +571,14 @@ extends: core
564
571
  # Reference core types in connections
565
572
  connectionTypes:
566
573
  - name: my_connection
567
- fromType: creator # From core
568
- toType: my_thing # From this feature
574
+ fromType: creator # From core
575
+ toType: my_thing # From this feature
569
576
  ```
570
577
 
571
578
  ### Issue: Performance with many types
572
579
 
573
580
  **Solution:**
581
+
574
582
  ```typescript
575
583
  // Cache type sets for O(1) lookup
576
584
  const THING_TYPE_SET = new Set(THING_TYPES);