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-developer-guide.md category.
13
13
  Location: one/knowledge/ontology-developer-guide.md
14
- Purpose: Documents multi-ontology architecture: developer guide
14
+ Purpose: Documents ONE Ontology architecture: developer guide
15
15
  Related dimensions: connections, events, people, things
16
16
  For AI agents: Read this to understand ontology developer guide.
17
17
  ---
18
18
 
19
- # Multi-Ontology Architecture: Developer Guide
19
+ # ONE Ontology Architecture: Developer Guide
20
20
 
21
21
  **Version:** 1.0.0
22
22
  **Last Updated:** 2025-10-20
@@ -66,7 +66,7 @@ type EntityType =
66
66
 
67
67
  ### The Solution: Composable Ontologies
68
68
 
69
- The multi-ontology architecture uses **feature-specific YAML files** that compose at runtime:
69
+ The ONE Ontology architecture uses **feature-specific YAML files** that compose at runtime:
70
70
 
71
71
  ```
72
72
  ┌─────────────────────────────────────┐
@@ -131,21 +131,25 @@ eventTypes: # OPTIONAL: Event types this feature adds
131
131
  ### Naming Conventions
132
132
 
133
133
  **Feature Names:**
134
+
134
135
  - Lowercase, no spaces
135
136
  - Use hyphens for multi-word features
136
137
  - Examples: `core`, `blog`, `shop`, `social-media`
137
138
 
138
139
  **Thing Type Names:**
140
+
139
141
  - Lowercase with underscores
140
142
  - Singular nouns
141
143
  - Examples: `blog_post`, `product`, `user`, `shopping_cart`
142
144
 
143
145
  **Connection Type Names:**
146
+
144
147
  - Lowercase with underscores
145
148
  - Action verbs (present tense)
146
149
  - Examples: `created_by`, `posted_in`, `purchased`, `in_stock`
147
150
 
148
151
  **Event Type Names:**
152
+
149
153
  - Lowercase with underscores
150
154
  - Past tense verbs
151
155
  - Examples: `blog_post_published`, `product_created`, `order_placed`
@@ -156,19 +160,19 @@ eventTypes: # OPTIONAL: Event types this feature adds
156
160
 
157
161
  ```yaml
158
162
  properties:
159
- name: string # Text
160
- age: number # Integer or float
161
- active: boolean # true/false
162
- metadata: object # JSON object (any structure)
163
+ name: string # Text
164
+ age: number # Integer or float
165
+ active: boolean # true/false
166
+ metadata: object # JSON object (any structure)
163
167
  ```
164
168
 
165
169
  **Array Types:**
166
170
 
167
171
  ```yaml
168
172
  properties:
169
- tags: string[] # Array of strings
170
- scores: number[] # Array of numbers
171
- items: object[] # Array of objects (not validated)
173
+ tags: string[] # Array of strings
174
+ scores: number[] # Array of numbers
175
+ items: object[] # Array of objects (not validated)
172
176
  ```
173
177
 
174
178
  **Complex Types:**
@@ -177,8 +181,8 @@ For complex nested structures, use `object`:
177
181
 
178
182
  ```yaml
179
183
  properties:
180
- address: object # { street, city, zip, country }
181
- settings: object # { theme, language, notifications }
184
+ address: object # { street, city, zip, country }
185
+ settings: object # { theme, language, notifications }
182
186
  ```
183
187
 
184
188
  > **Note:** Object properties are not validated by the type system. Validation happens at runtime in mutation handlers.
@@ -190,13 +194,13 @@ Features can inherit types from a base feature:
190
194
  ```yaml
191
195
  # ontology-blog.yaml
192
196
  feature: blog
193
- extends: core # Inherits: page, user, file, link, note
197
+ extends: core # Inherits: page, user, file, link, note
194
198
  description: Blog and content publishing
195
199
 
196
200
  thingTypes:
197
- - name: blog_post # ✅ Can use inherited types
201
+ - name: blog_post # ✅ Can use inherited types
198
202
  properties:
199
- authorId: string # ✅ References 'user' from core
203
+ authorId: string # ✅ References 'user' from core
200
204
  ```
201
205
 
202
206
  **Inheritance Rules:**
@@ -281,7 +285,7 @@ function resolveFeatureDependencies(features: string[]): string[] {
281
285
  function visit(feature: string, path: string[] = []) {
282
286
  // Detect circular dependencies
283
287
  if (path.includes(feature)) {
284
- throw new Error(`Circular dependency: ${path.join(' → ')} → ${feature}`);
288
+ throw new Error(`Circular dependency: ${path.join(" → ")} → ${feature}`);
285
289
  }
286
290
 
287
291
  // Skip if already resolved
@@ -349,8 +353,8 @@ feature: blog
349
353
  thingTypes:
350
354
  - name: blog_post
351
355
  - name: blog_category
352
- - name: product # ❌ Wrong feature!
353
- - name: shopping_cart # ❌ Wrong feature!
356
+ - name: product # ❌ Wrong feature!
357
+ - name: shopping_cart # ❌ Wrong feature!
354
358
  ```
355
359
 
356
360
  **Guideline:** If a type doesn't make sense without the feature, it belongs in that feature.
@@ -364,7 +368,7 @@ thingTypes:
364
368
  ```yaml
365
369
  # ontology-advanced-blog.yaml
366
370
  feature: advanced-blog
367
- extends: blog # ✅ Builds on top of blog
371
+ extends: blog # ✅ Builds on top of blog
368
372
  thingTypes:
369
373
  - name: blog_series
370
374
  - name: blog_newsletter
@@ -375,7 +379,7 @@ thingTypes:
375
379
  ```yaml
376
380
  # ontology-products.yaml
377
381
  feature: products
378
- extends: blog # ❌ Products have nothing to do with blog!
382
+ extends: blog # ❌ Products have nothing to do with blog!
379
383
  ```
380
384
 
381
385
  **Guideline:** Only extend features that are semantically related.
@@ -407,7 +411,7 @@ thingTypes:
407
411
  thingTypes:
408
412
  - name: product
409
413
  properties:
410
- data: object # ❌ Too vague!
414
+ data: object # ❌ Too vague!
411
415
  ```
412
416
 
413
417
  **Guideline:** Be explicit about properties. Use `object` only for truly dynamic data.
@@ -420,11 +424,11 @@ thingTypes:
420
424
 
421
425
  ```yaml
422
426
  connectionTypes:
423
- - name: purchased # ✅ Clear action
427
+ - name: purchased # ✅ Clear action
424
428
  fromType: user
425
429
  toType: product
426
430
 
427
- - name: in_cart # ✅ Clear state
431
+ - name: in_cart # ✅ Clear state
428
432
  fromType: user
429
433
  toType: product
430
434
  ```
@@ -433,7 +437,7 @@ connectionTypes:
433
437
 
434
438
  ```yaml
435
439
  connectionTypes:
436
- - name: user_product # ❌ Too vague!
440
+ - name: user_product # ❌ Too vague!
437
441
  fromType: user
438
442
  toType: product
439
443
  ```
@@ -457,8 +461,8 @@ eventTypes:
457
461
 
458
462
  ```yaml
459
463
  eventTypes:
460
- - name: create_product # ❌ Present tense!
461
- - name: place_order # ❌ Imperative!
464
+ - name: create_product # ❌ Present tense!
465
+ - name: place_order # ❌ Imperative!
462
466
  ```
463
467
 
464
468
  **Guideline:** Events describe what **happened** (past tense).
@@ -489,18 +493,18 @@ Each backend generates types for only its enabled features!
489
493
  ### Pattern 2: Feature Flags with Runtime Checks
490
494
 
491
495
  ```typescript
492
- import { hasFeature } from './types/ontology';
496
+ import { hasFeature } from "./types/ontology";
493
497
 
494
498
  export const createBlogPost = mutation({
495
499
  handler: async (ctx, args) => {
496
500
  // Runtime check
497
- if (!hasFeature('blog')) {
498
- throw new Error('Blog feature not enabled');
501
+ if (!hasFeature("blog")) {
502
+ throw new Error("Blog feature not enabled");
499
503
  }
500
504
 
501
505
  // Type-safe (TypeScript knows 'blog_post' exists)
502
- await ctx.db.insert('things', {
503
- type: 'blog_post',
506
+ await ctx.db.insert("things", {
507
+ type: "blog_post",
504
508
  // ...
505
509
  });
506
510
  },
@@ -541,9 +545,9 @@ PUBLIC_FEATURES="core,blog-v1,blog-v2"
541
545
 
542
546
  ```typescript
543
547
  // Load types dynamically based on environment
544
- const features = process.env.PUBLIC_FEATURES?.split(',') || ['core'];
548
+ const features = process.env.PUBLIC_FEATURES?.split(",") || ["core"];
545
549
 
546
- if (features.includes('blog')) {
550
+ if (features.includes("blog")) {
547
551
  // Blog-specific initialization
548
552
  }
549
553
  ```
@@ -562,7 +566,7 @@ description: Multi-vendor marketplace (combines shop + vendors)
562
566
 
563
567
  thingTypes:
564
568
  - name: vendor
565
- - name: vendor_product # Product with vendor info
569
+ - name: vendor_product # Product with vendor info
566
570
 
567
571
  connectionTypes:
568
572
  - name: sold_by
@@ -587,6 +591,7 @@ PUBLIC_FEATURES="core,blog"
587
591
  ```
588
592
 
589
593
  **Impact:**
594
+
590
595
  - Smaller TypeScript bundle
591
596
  - Faster type checking
592
597
  - Fewer database indexes
@@ -617,9 +622,9 @@ The generated `ontology.ts` file is deterministic. Cache it:
617
622
 
618
623
  ```typescript
619
624
  // Check if types are up-to-date
620
- const hash = hashFile('/one/knowledge/ontology-*.yaml');
625
+ const hash = hashFile("/one/knowledge/ontology-*.yaml");
621
626
  if (cachedHash === hash) {
622
- console.log('Types are up-to-date');
627
+ console.log("Types are up-to-date");
623
628
  return;
624
629
  }
625
630
 
@@ -635,18 +640,18 @@ Don't load validators for disabled features:
635
640
 
636
641
  ```typescript
637
642
  // ❌ Load all validators upfront
638
- import { validateBlogPost } from './validators/blog';
639
- import { validateProduct } from './validators/shop';
643
+ import { validateBlogPost } from "./validators/blog";
644
+ import { validateProduct } from "./validators/shop";
640
645
 
641
646
  // ✅ Lazy load only when needed
642
647
  const validators = {
643
648
  get blog_post() {
644
- if (!hasFeature('blog')) throw new Error('Blog not enabled');
645
- return require('./validators/blog').validateBlogPost;
649
+ if (!hasFeature("blog")) throw new Error("Blog not enabled");
650
+ return require("./validators/blog").validateBlogPost;
646
651
  },
647
652
  get product() {
648
- if (!hasFeature('shop')) throw new Error('Shop not enabled');
649
- return require('./validators/shop').validateProduct;
653
+ if (!hasFeature("shop")) throw new Error("Shop not enabled");
654
+ return require("./validators/shop").validateProduct;
650
655
  },
651
656
  };
652
657
  ```
@@ -658,26 +663,26 @@ const validators = {
658
663
  ### 1. Test Ontology Loading
659
664
 
660
665
  ```typescript
661
- import { describe, it, expect } from 'bun:test';
662
- import { loadOntology } from './scripts/generate-ontology-types';
663
-
664
- describe('Ontology Loading', () => {
665
- it('should load core ontology', () => {
666
- const core = loadOntology('core');
667
- expect(core.thingTypes).toContain('page');
668
- expect(core.thingTypes).toContain('user');
666
+ import { describe, it, expect } from "bun:test";
667
+ import { loadOntology } from "./scripts/generate-ontology-types";
668
+
669
+ describe("Ontology Loading", () => {
670
+ it("should load core ontology", () => {
671
+ const core = loadOntology("core");
672
+ expect(core.thingTypes).toContain("page");
673
+ expect(core.thingTypes).toContain("user");
669
674
  });
670
675
 
671
- it('should resolve dependencies', () => {
672
- const features = ['blog', 'shop'];
676
+ it("should resolve dependencies", () => {
677
+ const features = ["blog", "shop"];
673
678
  const resolved = resolveFeatureDependencies(features);
674
- expect(resolved).toEqual(['core', 'blog', 'shop']);
679
+ expect(resolved).toEqual(["core", "blog", "shop"]);
675
680
  });
676
681
 
677
- it('should detect circular dependencies', () => {
682
+ it("should detect circular dependencies", () => {
678
683
  expect(() => {
679
- resolveFeatureDependencies(['circular-a', 'circular-b']);
680
- }).toThrow('Circular dependency');
684
+ resolveFeatureDependencies(["circular-a", "circular-b"]);
685
+ }).toThrow("Circular dependency");
681
686
  });
682
687
  });
683
688
  ```
@@ -687,20 +692,20 @@ describe('Ontology Loading', () => {
687
692
  ### 2. Test Type Guards
688
693
 
689
694
  ```typescript
690
- describe('Type Guards', () => {
691
- it('should validate thing types', () => {
692
- expect(isThingType('blog_post')).toBe(true);
693
- expect(isThingType('invalid')).toBe(false);
695
+ describe("Type Guards", () => {
696
+ it("should validate thing types", () => {
697
+ expect(isThingType("blog_post")).toBe(true);
698
+ expect(isThingType("invalid")).toBe(false);
694
699
  });
695
700
 
696
- it('should validate connection types', () => {
697
- expect(isConnectionType('created_by')).toBe(true);
698
- expect(isConnectionType('invalid')).toBe(false);
701
+ it("should validate connection types", () => {
702
+ expect(isConnectionType("created_by")).toBe(true);
703
+ expect(isConnectionType("invalid")).toBe(false);
699
704
  });
700
705
 
701
- it('should validate event types', () => {
702
- expect(isEventType('thing_created')).toBe(true);
703
- expect(isEventType('invalid')).toBe(false);
706
+ it("should validate event types", () => {
707
+ expect(isEventType("thing_created")).toBe(true);
708
+ expect(isEventType("invalid")).toBe(false);
704
709
  });
705
710
  });
706
711
  ```
@@ -710,16 +715,16 @@ describe('Type Guards', () => {
710
715
  ### 3. Test Feature Flags
711
716
 
712
717
  ```typescript
713
- describe('Feature Flags', () => {
714
- it('should detect enabled features', () => {
715
- process.env.PUBLIC_FEATURES = 'core,blog';
716
- expect(hasFeature('blog')).toBe(true);
717
- expect(hasFeature('shop')).toBe(false);
718
+ describe("Feature Flags", () => {
719
+ it("should detect enabled features", () => {
720
+ process.env.PUBLIC_FEATURES = "core,blog";
721
+ expect(hasFeature("blog")).toBe(true);
722
+ expect(hasFeature("shop")).toBe(false);
718
723
  });
719
724
 
720
- it('should list all enabled features', () => {
721
- process.env.PUBLIC_FEATURES = 'core,blog,shop';
722
- expect(ENABLED_FEATURES).toEqual(['core', 'blog', 'shop']);
725
+ it("should list all enabled features", () => {
726
+ process.env.PUBLIC_FEATURES = "core,blog,shop";
727
+ expect(ENABLED_FEATURES).toEqual(["core", "blog", "shop"]);
723
728
  });
724
729
  });
725
730
  ```
@@ -731,32 +736,34 @@ describe('Feature Flags', () => {
731
736
  Test mutations with different feature sets:
732
737
 
733
738
  ```typescript
734
- describe('Blog Mutations (blog enabled)', () => {
739
+ describe("Blog Mutations (blog enabled)", () => {
735
740
  beforeAll(() => {
736
- process.env.PUBLIC_FEATURES = 'core,blog';
741
+ process.env.PUBLIC_FEATURES = "core,blog";
737
742
  regenerateTypes();
738
743
  });
739
744
 
740
- it('should create blog post', async () => {
745
+ it("should create blog post", async () => {
741
746
  const id = await createBlogPost({
742
- title: 'Test Post',
743
- content: 'Content',
747
+ title: "Test Post",
748
+ content: "Content",
744
749
  });
745
750
  expect(id).toBeDefined();
746
751
  });
747
752
  });
748
753
 
749
- describe('Blog Mutations (blog disabled)', () => {
754
+ describe("Blog Mutations (blog disabled)", () => {
750
755
  beforeAll(() => {
751
- process.env.PUBLIC_FEATURES = 'core';
756
+ process.env.PUBLIC_FEATURES = "core";
752
757
  regenerateTypes();
753
758
  });
754
759
 
755
- it('should reject blog post creation', async () => {
756
- await expect(createBlogPost({
757
- title: 'Test Post',
758
- content: 'Content',
759
- })).rejects.toThrow('Blog feature not enabled');
760
+ it("should reject blog post creation", async () => {
761
+ await expect(
762
+ createBlogPost({
763
+ title: "Test Post",
764
+ content: "Content",
765
+ })
766
+ ).rejects.toThrow("Blog feature not enabled");
760
767
  });
761
768
  });
762
769
  ```
@@ -791,7 +798,7 @@ ONTOLOGY_DEBUG=true bun run scripts/generate-ontology-types.ts
791
798
 
792
799
  ## Summary
793
800
 
794
- The multi-ontology architecture provides:
801
+ The ONE Ontology architecture provides:
795
802
 
796
803
  ✅ **Composability** - Features are independent and composable
797
804
  ✅ **Type Safety** - Full TypeScript validation