@soulcraft/brainy 3.17.0 → 3.18.0

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.
Files changed (38) hide show
  1. package/README.md +5 -6
  2. package/dist/augmentations/defaultAugmentations.d.ts +0 -1
  3. package/dist/augmentations/defaultAugmentations.js +0 -5
  4. package/dist/brainy.d.ts +46 -0
  5. package/dist/brainy.js +53 -0
  6. package/dist/neural/embeddedPatterns.d.ts +1 -1
  7. package/dist/neural/embeddedPatterns.js +1 -1
  8. package/dist/neural/naturalLanguageProcessor.js +0 -1
  9. package/dist/setup.js +0 -1
  10. package/dist/unified.js +0 -1
  11. package/dist/vfs/VirtualFileSystem.d.ts +6 -4
  12. package/dist/vfs/VirtualFileSystem.js +44 -21
  13. package/dist/vfs/index.d.ts +0 -5
  14. package/dist/vfs/index.js +0 -6
  15. package/dist/vfs/semantic/ProjectionRegistry.d.ts +84 -0
  16. package/dist/vfs/semantic/ProjectionRegistry.js +118 -0
  17. package/dist/vfs/semantic/ProjectionStrategy.d.ts +69 -0
  18. package/dist/vfs/semantic/ProjectionStrategy.js +40 -0
  19. package/dist/vfs/semantic/SemanticPathParser.d.ts +73 -0
  20. package/dist/vfs/semantic/SemanticPathParser.js +285 -0
  21. package/dist/vfs/semantic/SemanticPathResolver.d.ts +99 -0
  22. package/dist/vfs/semantic/SemanticPathResolver.js +242 -0
  23. package/dist/vfs/semantic/index.d.ts +17 -0
  24. package/dist/vfs/semantic/index.js +18 -0
  25. package/dist/vfs/semantic/projections/AuthorProjection.d.ts +35 -0
  26. package/dist/vfs/semantic/projections/AuthorProjection.js +74 -0
  27. package/dist/vfs/semantic/projections/ConceptProjection.d.ts +42 -0
  28. package/dist/vfs/semantic/projections/ConceptProjection.js +87 -0
  29. package/dist/vfs/semantic/projections/RelationshipProjection.d.ts +41 -0
  30. package/dist/vfs/semantic/projections/RelationshipProjection.js +101 -0
  31. package/dist/vfs/semantic/projections/SimilarityProjection.d.ts +36 -0
  32. package/dist/vfs/semantic/projections/SimilarityProjection.js +77 -0
  33. package/dist/vfs/semantic/projections/TagProjection.d.ts +34 -0
  34. package/dist/vfs/semantic/projections/TagProjection.js +73 -0
  35. package/dist/vfs/semantic/projections/TemporalProjection.d.ts +35 -0
  36. package/dist/vfs/semantic/projections/TemporalProjection.js +89 -0
  37. package/dist/vfs/types.d.ts +1 -8
  38. package/package.json +1 -1
package/README.md CHANGED
@@ -767,13 +767,12 @@ We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
767
767
  - [Next.js Integration](docs/guides/nextjs-integration.md) - **NEW!** React and Next.js examples
768
768
  - [Vue.js Integration](docs/guides/vue-integration.md) - **NEW!** Vue and Nuxt examples
769
769
 
770
- ### Virtual Filesystem & Knowledge Layer 🧠📁
771
- - [VFS Core Documentation](docs/vfs/VFS_CORE.md) - **NEW!** Complete filesystem architecture and API
772
- - [VFS + Knowledge Layer](docs/vfs/VFS_KNOWLEDGE_LAYER.md) - **NEW!** Intelligent knowledge management features
773
- - [Examples & Scenarios](docs/vfs/VFS_EXAMPLES_SCENARIOS.md) - **NEW!** Real-world use cases and code
770
+ ### Virtual Filesystem (Semantic VFS) 🧠📁
771
+ - [VFS Core Documentation](docs/vfs/VFS_CORE.md) - Complete filesystem architecture and API
772
+ - [Semantic VFS Guide](docs/vfs/SEMANTIC_VFS.md) - Multi-dimensional file access (6 semantic dimensions)
773
+ - [Neural Extraction API](docs/vfs/NEURAL_EXTRACTION.md) - AI-powered concept and entity extraction
774
+ - [Examples & Scenarios](docs/vfs/VFS_EXAMPLES_SCENARIOS.md) - Real-world use cases and code
774
775
  - [VFS API Guide](docs/vfs/VFS_API_GUIDE.md) - Complete API reference
775
- - [Knowledge Layer API](docs/vfs/KNOWLEDGE_LAYER_API.md) - Advanced knowledge features
776
- - [Knowledge Layer Overview](docs/KNOWLEDGE_LAYER_OVERVIEW.md) - Non-technical guide
777
776
 
778
777
  ### Core Documentation
779
778
  - [Getting Started Guide](docs/guides/getting-started.md)
@@ -25,7 +25,6 @@ export declare function createDefaultAugmentations(config?: {
25
25
  metrics?: boolean | Record<string, any>;
26
26
  monitoring?: boolean | Record<string, any>;
27
27
  display?: boolean | Record<string, any>;
28
- knowledge?: boolean | Record<string, any>;
29
28
  }): BaseAugmentation[];
30
29
  /**
31
30
  * Get augmentation by name with type safety
@@ -11,7 +11,6 @@ import { CacheAugmentation } from './cacheAugmentation.js';
11
11
  import { MetricsAugmentation } from './metricsAugmentation.js';
12
12
  import { MonitoringAugmentation } from './monitoringAugmentation.js';
13
13
  import { UniversalDisplayAugmentation } from './universalDisplayAugmentation.js';
14
- import { KnowledgeAugmentation } from './KnowledgeAugmentation.js';
15
14
  /**
16
15
  * Create default augmentations for zero-config operation
17
16
  * Returns an array of augmentations to be registered
@@ -45,10 +44,6 @@ export function createDefaultAugmentations(config = {}) {
45
44
  const monitoringConfig = typeof config.monitoring === 'object' ? config.monitoring : {};
46
45
  augmentations.push(new MonitoringAugmentation(monitoringConfig));
47
46
  }
48
- // Knowledge Layer augmentation for VFS intelligence
49
- if (config.knowledge !== false) {
50
- augmentations.push(new KnowledgeAugmentation());
51
- }
52
47
  return augmentations;
53
48
  }
54
49
  /**
package/dist/brainy.d.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  import { Vector } from './coreTypes.js';
8
8
  import { ImprovedNeuralAPI } from './neural/improvedNeuralAPI.js';
9
9
  import { NaturalLanguageProcessor } from './neural/naturalLanguageProcessor.js';
10
+ import { ExtractedEntity } from './neural/entityExtractor.js';
10
11
  import { TripleIntelligenceSystem } from './triple/TripleIntelligenceSystem.js';
11
12
  import { VirtualFileSystem } from './vfs/VirtualFileSystem.js';
12
13
  import { Entity, Relation, Result, AddParams, UpdateParams, RelateParams, FindParams, SimilarParams, GetRelationsParams, AddManyParams, DeleteManyParams, RelateManyParams, BatchResult, BrainyConfig } from './types/brainy.types.js';
@@ -34,6 +35,7 @@ export declare class Brainy<T = any> implements BrainyInterface<T> {
34
35
  private originalConsole?;
35
36
  private _neural?;
36
37
  private _nlp?;
38
+ private _extractor?;
37
39
  private _tripleIntelligence?;
38
40
  private _vfs?;
39
41
  private initialized;
@@ -594,6 +596,50 @@ export declare class Brainy<T = any> implements BrainyInterface<T> {
594
596
  * Natural Language Processing API
595
597
  */
596
598
  nlp(): NaturalLanguageProcessor;
599
+ /**
600
+ * Entity Extraction API - Neural extraction with NounType taxonomy
601
+ *
602
+ * Extracts entities from text using:
603
+ * - Pattern-based candidate detection
604
+ * - Embedding-based type classification
605
+ * - Context-aware confidence scoring
606
+ *
607
+ * @param text - Text to extract entities from
608
+ * @param options - Extraction options
609
+ * @returns Array of extracted entities with types and confidence
610
+ *
611
+ * @example
612
+ * const entities = await brain.extract('John Smith founded Acme Corp in New York')
613
+ * // [
614
+ * // { text: 'John Smith', type: NounType.Person, confidence: 0.95 },
615
+ * // { text: 'Acme Corp', type: NounType.Organization, confidence: 0.92 },
616
+ * // { text: 'New York', type: NounType.Location, confidence: 0.88 }
617
+ * // ]
618
+ */
619
+ extract(text: string, options?: {
620
+ types?: NounType[];
621
+ confidence?: number;
622
+ includeVectors?: boolean;
623
+ neuralMatching?: boolean;
624
+ }): Promise<ExtractedEntity[]>;
625
+ /**
626
+ * Extract concepts from text
627
+ *
628
+ * Simplified interface for concept/topic extraction
629
+ * Returns only concept names as strings for easy metadata population
630
+ *
631
+ * @param text - Text to extract concepts from
632
+ * @param options - Extraction options
633
+ * @returns Array of concept names
634
+ *
635
+ * @example
636
+ * const concepts = await brain.extractConcepts('Using OAuth for authentication')
637
+ * // ['oauth', 'authentication']
638
+ */
639
+ extractConcepts(text: string, options?: {
640
+ confidence?: number;
641
+ limit?: number;
642
+ }): Promise<string[]>;
597
643
  /**
598
644
  * Virtual File System API - Knowledge Operating System
599
645
  */
package/dist/brainy.js CHANGED
@@ -13,6 +13,7 @@ import { AugmentationRegistry } from './augmentations/brainyAugmentation.js';
13
13
  import { createDefaultAugmentations } from './augmentations/defaultAugmentations.js';
14
14
  import { ImprovedNeuralAPI } from './neural/improvedNeuralAPI.js';
15
15
  import { NaturalLanguageProcessor } from './neural/naturalLanguageProcessor.js';
16
+ import { NeuralEntityExtractor } from './neural/entityExtractor.js';
16
17
  import { TripleIntelligenceSystem } from './triple/TripleIntelligenceSystem.js';
17
18
  import { VirtualFileSystem } from './vfs/VirtualFileSystem.js';
18
19
  import { MetadataIndexManager } from './utils/metadataIndex.js';
@@ -1357,6 +1358,58 @@ export class Brainy {
1357
1358
  }
1358
1359
  return this._nlp;
1359
1360
  }
1361
+ /**
1362
+ * Entity Extraction API - Neural extraction with NounType taxonomy
1363
+ *
1364
+ * Extracts entities from text using:
1365
+ * - Pattern-based candidate detection
1366
+ * - Embedding-based type classification
1367
+ * - Context-aware confidence scoring
1368
+ *
1369
+ * @param text - Text to extract entities from
1370
+ * @param options - Extraction options
1371
+ * @returns Array of extracted entities with types and confidence
1372
+ *
1373
+ * @example
1374
+ * const entities = await brain.extract('John Smith founded Acme Corp in New York')
1375
+ * // [
1376
+ * // { text: 'John Smith', type: NounType.Person, confidence: 0.95 },
1377
+ * // { text: 'Acme Corp', type: NounType.Organization, confidence: 0.92 },
1378
+ * // { text: 'New York', type: NounType.Location, confidence: 0.88 }
1379
+ * // ]
1380
+ */
1381
+ async extract(text, options) {
1382
+ if (!this._extractor) {
1383
+ this._extractor = new NeuralEntityExtractor(this);
1384
+ }
1385
+ return await this._extractor.extract(text, options);
1386
+ }
1387
+ /**
1388
+ * Extract concepts from text
1389
+ *
1390
+ * Simplified interface for concept/topic extraction
1391
+ * Returns only concept names as strings for easy metadata population
1392
+ *
1393
+ * @param text - Text to extract concepts from
1394
+ * @param options - Extraction options
1395
+ * @returns Array of concept names
1396
+ *
1397
+ * @example
1398
+ * const concepts = await brain.extractConcepts('Using OAuth for authentication')
1399
+ * // ['oauth', 'authentication']
1400
+ */
1401
+ async extractConcepts(text, options) {
1402
+ const entities = await this.extract(text, {
1403
+ types: [NounType.Concept, NounType.Topic],
1404
+ confidence: options?.confidence || 0.7,
1405
+ neuralMatching: true
1406
+ });
1407
+ // Deduplicate and normalize
1408
+ const conceptSet = new Set(entities.map(e => e.text.toLowerCase()));
1409
+ const concepts = Array.from(conceptSet);
1410
+ // Apply limit if specified
1411
+ return options?.limit ? concepts.slice(0, options.limit) : concepts;
1412
+ }
1360
1413
  /**
1361
1414
  * Virtual File System API - Knowledge Operating System
1362
1415
  */
@@ -2,7 +2,7 @@
2
2
  * 🧠 BRAINY EMBEDDED PATTERNS
3
3
  *
4
4
  * AUTO-GENERATED - DO NOT EDIT
5
- * Generated: 2025-09-15T16:41:42.483Z
5
+ * Generated: 2025-09-29T17:05:30.153Z
6
6
  * Patterns: 220
7
7
  * Coverage: 94-98% of all queries
8
8
  *
@@ -2,7 +2,7 @@
2
2
  * 🧠 BRAINY EMBEDDED PATTERNS
3
3
  *
4
4
  * AUTO-GENERATED - DO NOT EDIT
5
- * Generated: 2025-09-15T16:41:42.483Z
5
+ * Generated: 2025-09-29T17:05:30.153Z
6
6
  * Patterns: 220
7
7
  * Coverage: 94-98% of all queries
8
8
  *
@@ -1015,7 +1015,6 @@ export class NaturalLanguageProcessor {
1015
1015
  confidence
1016
1016
  };
1017
1017
  if (options?.includeMetadata) {
1018
- ;
1019
1018
  entity.metadata = {
1020
1019
  pattern: pattern.source,
1021
1020
  contextBefore: text.substring(Math.max(0, match.index - 20), match.index),
package/dist/setup.js CHANGED
@@ -34,7 +34,6 @@ if (globalObj) {
34
34
  globalObj.TextDecoder = TextDecoder;
35
35
  }
36
36
  // Create special global constructors for library compatibility
37
- ;
38
37
  globalObj.__TextEncoder__ = TextEncoder;
39
38
  globalObj.__TextDecoder__ = TextDecoder;
40
39
  }
package/dist/unified.js CHANGED
@@ -41,7 +41,6 @@ export const environment = {
41
41
  };
42
42
  // Make environment information available globally
43
43
  if (typeof globalThis !== 'undefined') {
44
- ;
45
44
  globalThis.__ENV__ = environment;
46
45
  }
47
46
  // Log the detected environment
@@ -19,6 +19,7 @@ import { IVirtualFileSystem, VFSConfig, VFSEntity, VFSMetadata, VFSStats, VFSDir
19
19
  export declare class VirtualFileSystem implements IVirtualFileSystem {
20
20
  private brain;
21
21
  private pathResolver;
22
+ private projectionRegistry;
22
23
  private config;
23
24
  private rootEntityId?;
24
25
  private initialized;
@@ -35,6 +36,11 @@ export declare class VirtualFileSystem implements IVirtualFileSystem {
35
36
  /**
36
37
  * Create or find the root directory entity
37
38
  */
39
+ /**
40
+ * Auto-register built-in projection strategies
41
+ * Zero-config: All semantic dimensions work out of the box
42
+ */
43
+ private registerBuiltInProjections;
38
44
  private initializeRoot;
39
45
  /**
40
46
  * Read a file's content
@@ -183,10 +189,6 @@ export declare class VirtualFileSystem implements IVirtualFileSystem {
183
189
  * Merges with existing metadata
184
190
  */
185
191
  setMetadata(path: string, metadata: Partial<VFSMetadata>): Promise<void>;
186
- /**
187
- * Enable Knowledge Layer on this VFS instance
188
- */
189
- enableKnowledgeLayer(): Promise<void>;
190
192
  /**
191
193
  * Set the current user for tracking who makes changes
192
194
  */
@@ -7,8 +7,8 @@
7
7
  import crypto from 'crypto';
8
8
  import { Brainy } from '../brainy.js';
9
9
  import { NounType, VerbType } from '../types/graphTypes.js';
10
- import { PathResolver } from './PathResolver.js';
11
- // Knowledge Layer imports removed - now in KnowledgeAugmentation
10
+ import { SemanticPathResolver, ProjectionRegistry, ConceptProjection, AuthorProjection, TemporalProjection, RelationshipProjection, SimilarityProjection, TagProjection } from './semantic/index.js';
11
+ // Knowledge Layer can remain as optional augmentation for now
12
12
  import { VFSError, VFSErrorCode } from './types.js';
13
13
  /**
14
14
  * Main Virtual Filesystem Implementation
@@ -46,12 +46,12 @@ export class VirtualFileSystem {
46
46
  }
47
47
  // Create or find root entity
48
48
  this.rootEntityId = await this.initializeRoot();
49
- // Initialize path resolver
50
- this.pathResolver = new PathResolver(this.brain, this.rootEntityId, {
51
- maxCacheSize: this.config.cache?.maxPaths,
52
- cacheTTL: this.config.cache?.ttl,
53
- hotPathThreshold: 10
54
- });
49
+ // Initialize projection registry with auto-discovery of built-in projections
50
+ this.projectionRegistry = new ProjectionRegistry();
51
+ this.registerBuiltInProjections();
52
+ // Initialize semantic path resolver (zero-config, uses brain.config)
53
+ this.pathResolver = new SemanticPathResolver(this.brain, this, // Pass VFS instance for resolvePath
54
+ this.rootEntityId, this.projectionRegistry);
55
55
  // Knowledge Layer is now a separate augmentation
56
56
  // Enable with: brain.use('knowledge')
57
57
  // Start background tasks
@@ -61,6 +61,31 @@ export class VirtualFileSystem {
61
61
  /**
62
62
  * Create or find the root directory entity
63
63
  */
64
+ /**
65
+ * Auto-register built-in projection strategies
66
+ * Zero-config: All semantic dimensions work out of the box
67
+ */
68
+ registerBuiltInProjections() {
69
+ const projections = [
70
+ ConceptProjection,
71
+ AuthorProjection,
72
+ TemporalProjection,
73
+ RelationshipProjection,
74
+ SimilarityProjection,
75
+ TagProjection
76
+ ];
77
+ for (const ProjectionClass of projections) {
78
+ try {
79
+ this.projectionRegistry.register(new ProjectionClass());
80
+ }
81
+ catch (err) {
82
+ // Silently skip if already registered (e.g., in tests)
83
+ if (!(err instanceof Error && err.message.includes('already registered'))) {
84
+ throw err;
85
+ }
86
+ }
87
+ }
88
+ }
64
89
  async initializeRoot() {
65
90
  // Check if root already exists - search using where clause
66
91
  const existing = await this.brain.find({
@@ -1026,6 +1051,17 @@ export class VirtualFileSystem {
1026
1051
  metadata.lineCount = text.split('\n').length;
1027
1052
  metadata.wordCount = text.split(/\s+/).filter(w => w).length;
1028
1053
  metadata.charset = 'utf-8';
1054
+ // Extract concepts using brain.extractConcepts() (neural extraction)
1055
+ if (this.config.intelligence?.autoConcepts) {
1056
+ try {
1057
+ const concepts = await this.brain.extractConcepts(text, { limit: 20 });
1058
+ metadata.conceptNames = concepts; // Flattened for O(log n) queries
1059
+ }
1060
+ catch (error) {
1061
+ // Concept extraction is optional - don't fail if it errors
1062
+ console.debug('Concept extraction failed:', error);
1063
+ }
1064
+ }
1029
1065
  }
1030
1066
  // Extract hash for integrity
1031
1067
  const crypto = await import('crypto');
@@ -1193,9 +1229,6 @@ export class VirtualFileSystem {
1193
1229
  maxFileSize: 1000000000, // 1GB
1194
1230
  maxPathLength: 4096,
1195
1231
  maxDirectoryEntries: 100000
1196
- },
1197
- knowledgeLayer: {
1198
- enabled: false // Default to disabled
1199
1232
  }
1200
1233
  };
1201
1234
  }
@@ -1732,16 +1765,6 @@ export class VirtualFileSystem {
1732
1765
  // Invalidate caches
1733
1766
  this.invalidateCaches(path);
1734
1767
  }
1735
- // ============= Knowledge Layer =============
1736
- // Knowledge Layer methods are added by KnowledgeLayer.enable()
1737
- // This keeps VFS pure and fast while allowing optional intelligence
1738
- /**
1739
- * Enable Knowledge Layer on this VFS instance
1740
- */
1741
- async enableKnowledgeLayer() {
1742
- const { enableKnowledgeLayer } = await import('./KnowledgeLayer.js');
1743
- await enableKnowledgeLayer(this, this.brain);
1744
- }
1745
1768
  /**
1746
1769
  * Set the current user for tracking who makes changes
1747
1770
  */
@@ -11,9 +11,4 @@ export { FSCompat, createFS } from './FSCompat.js';
11
11
  export { DirectoryImporter } from './importers/DirectoryImporter.js';
12
12
  export { VFSReadStream } from './streams/VFSReadStream.js';
13
13
  export { VFSWriteStream } from './streams/VFSWriteStream.js';
14
- export { EventRecorder } from './EventRecorder.js';
15
- export { SemanticVersioning } from './SemanticVersioning.js';
16
- export { PersistentEntitySystem } from './PersistentEntitySystem.js';
17
- export { ConceptSystem } from './ConceptSystem.js';
18
- export { GitBridge } from './GitBridge.js';
19
14
  export { VirtualFileSystem as VFS } from './VirtualFileSystem.js';
package/dist/vfs/index.js CHANGED
@@ -15,12 +15,6 @@ export { DirectoryImporter } from './importers/DirectoryImporter.js';
15
15
  // Streaming
16
16
  export { VFSReadStream } from './streams/VFSReadStream.js';
17
17
  export { VFSWriteStream } from './streams/VFSWriteStream.js';
18
- // Knowledge Layer Components (optional via augmentation)
19
- export { EventRecorder } from './EventRecorder.js';
20
- export { SemanticVersioning } from './SemanticVersioning.js';
21
- export { PersistentEntitySystem } from './PersistentEntitySystem.js';
22
- export { ConceptSystem } from './ConceptSystem.js';
23
- export { GitBridge } from './GitBridge.js';
24
18
  // Convenience alias
25
19
  export { VirtualFileSystem as VFS } from './VirtualFileSystem.js';
26
20
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Projection Registry
3
+ *
4
+ * Central registry for all projection strategies
5
+ * Manages strategy lookup and execution
6
+ */
7
+ import { ProjectionStrategy } from './ProjectionStrategy.js';
8
+ import { Brainy } from '../../brainy.js';
9
+ import { VirtualFileSystem } from '../VirtualFileSystem.js';
10
+ import { VFSEntity } from '../types.js';
11
+ /**
12
+ * Registry for projection strategies
13
+ * Allows dynamic registration and lookup of strategies
14
+ */
15
+ export declare class ProjectionRegistry {
16
+ private strategies;
17
+ /**
18
+ * Register a projection strategy
19
+ * @param strategy - The strategy to register
20
+ * @throws Error if strategy with same name already registered
21
+ */
22
+ register(strategy: ProjectionStrategy): void;
23
+ /**
24
+ * Get a projection strategy by name
25
+ * @param name - Strategy name
26
+ * @returns The strategy or undefined if not found
27
+ */
28
+ get(name: string): ProjectionStrategy | undefined;
29
+ /**
30
+ * Check if a strategy is registered
31
+ * @param name - Strategy name
32
+ */
33
+ has(name: string): boolean;
34
+ /**
35
+ * List all registered strategy names
36
+ */
37
+ listDimensions(): string[];
38
+ /**
39
+ * Get count of registered strategies
40
+ */
41
+ count(): number;
42
+ /**
43
+ * Resolve a dimension value to entity IDs
44
+ * Convenience method that looks up strategy and calls resolve()
45
+ *
46
+ * @param dimension - The semantic dimension
47
+ * @param value - The value to resolve
48
+ * @param brain - REAL Brainy instance
49
+ * @param vfs - REAL VirtualFileSystem instance
50
+ * @returns Array of entity IDs
51
+ * @throws Error if dimension not registered
52
+ */
53
+ resolve(dimension: string, value: any, brain: Brainy, vfs: VirtualFileSystem): Promise<string[]>;
54
+ /**
55
+ * List entities in a dimension
56
+ * Convenience method for strategies that support listing
57
+ *
58
+ * @param dimension - The semantic dimension
59
+ * @param brain - REAL Brainy instance
60
+ * @param vfs - REAL VirtualFileSystem instance
61
+ * @param limit - Max results
62
+ * @returns Array of VFSEntity
63
+ * @throws Error if dimension not registered or doesn't support listing
64
+ */
65
+ list(dimension: string, brain: Brainy, vfs: VirtualFileSystem, limit?: number): Promise<VFSEntity[]>;
66
+ /**
67
+ * Unregister a strategy
68
+ * Useful for testing or dynamic strategy management
69
+ *
70
+ * @param name - Strategy name to remove
71
+ * @returns true if removed, false if not found
72
+ */
73
+ unregister(name: string): boolean;
74
+ /**
75
+ * Clear all registered strategies
76
+ * Useful for testing
77
+ */
78
+ clear(): void;
79
+ /**
80
+ * Get all registered strategies
81
+ * Returns a copy to prevent external modification
82
+ */
83
+ getAll(): ProjectionStrategy[];
84
+ }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Projection Registry
3
+ *
4
+ * Central registry for all projection strategies
5
+ * Manages strategy lookup and execution
6
+ */
7
+ /**
8
+ * Registry for projection strategies
9
+ * Allows dynamic registration and lookup of strategies
10
+ */
11
+ export class ProjectionRegistry {
12
+ constructor() {
13
+ this.strategies = new Map();
14
+ }
15
+ /**
16
+ * Register a projection strategy
17
+ * @param strategy - The strategy to register
18
+ * @throws Error if strategy with same name already registered
19
+ */
20
+ register(strategy) {
21
+ if (this.strategies.has(strategy.name)) {
22
+ throw new Error(`Projection strategy '${strategy.name}' is already registered`);
23
+ }
24
+ this.strategies.set(strategy.name, strategy);
25
+ }
26
+ /**
27
+ * Get a projection strategy by name
28
+ * @param name - Strategy name
29
+ * @returns The strategy or undefined if not found
30
+ */
31
+ get(name) {
32
+ return this.strategies.get(name);
33
+ }
34
+ /**
35
+ * Check if a strategy is registered
36
+ * @param name - Strategy name
37
+ */
38
+ has(name) {
39
+ return this.strategies.has(name);
40
+ }
41
+ /**
42
+ * List all registered strategy names
43
+ */
44
+ listDimensions() {
45
+ return Array.from(this.strategies.keys());
46
+ }
47
+ /**
48
+ * Get count of registered strategies
49
+ */
50
+ count() {
51
+ return this.strategies.size;
52
+ }
53
+ /**
54
+ * Resolve a dimension value to entity IDs
55
+ * Convenience method that looks up strategy and calls resolve()
56
+ *
57
+ * @param dimension - The semantic dimension
58
+ * @param value - The value to resolve
59
+ * @param brain - REAL Brainy instance
60
+ * @param vfs - REAL VirtualFileSystem instance
61
+ * @returns Array of entity IDs
62
+ * @throws Error if dimension not registered
63
+ */
64
+ async resolve(dimension, value, brain, vfs) {
65
+ const strategy = this.get(dimension);
66
+ if (!strategy) {
67
+ throw new Error(`Unknown projection dimension: ${dimension}. Registered dimensions: ${this.listDimensions().join(', ')}`);
68
+ }
69
+ // Call REAL strategy resolve method
70
+ return await strategy.resolve(brain, vfs, value);
71
+ }
72
+ /**
73
+ * List entities in a dimension
74
+ * Convenience method for strategies that support listing
75
+ *
76
+ * @param dimension - The semantic dimension
77
+ * @param brain - REAL Brainy instance
78
+ * @param vfs - REAL VirtualFileSystem instance
79
+ * @param limit - Max results
80
+ * @returns Array of VFSEntity
81
+ * @throws Error if dimension not registered or doesn't support listing
82
+ */
83
+ async list(dimension, brain, vfs, limit) {
84
+ const strategy = this.get(dimension);
85
+ if (!strategy) {
86
+ throw new Error(`Unknown projection dimension: ${dimension}`);
87
+ }
88
+ if (!strategy.list) {
89
+ throw new Error(`Projection '${dimension}' does not support listing`);
90
+ }
91
+ return await strategy.list(brain, vfs, limit);
92
+ }
93
+ /**
94
+ * Unregister a strategy
95
+ * Useful for testing or dynamic strategy management
96
+ *
97
+ * @param name - Strategy name to remove
98
+ * @returns true if removed, false if not found
99
+ */
100
+ unregister(name) {
101
+ return this.strategies.delete(name);
102
+ }
103
+ /**
104
+ * Clear all registered strategies
105
+ * Useful for testing
106
+ */
107
+ clear() {
108
+ this.strategies.clear();
109
+ }
110
+ /**
111
+ * Get all registered strategies
112
+ * Returns a copy to prevent external modification
113
+ */
114
+ getAll() {
115
+ return Array.from(this.strategies.values());
116
+ }
117
+ }
118
+ //# sourceMappingURL=ProjectionRegistry.js.map
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Projection Strategy Interface
3
+ *
4
+ * Defines how to map semantic path dimensions to Brainy queries
5
+ * Each strategy uses EXISTING Brainy indexes and methods
6
+ */
7
+ import { Brainy } from '../../brainy.js';
8
+ import { VirtualFileSystem } from '../VirtualFileSystem.js';
9
+ import { FindParams } from '../../types/brainy.types.js';
10
+ import { VFSEntity } from '../types.js';
11
+ /**
12
+ * Strategy for projecting semantic paths into entity queries
13
+ * All implementations MUST use real Brainy methods (no stubs!)
14
+ */
15
+ export interface ProjectionStrategy {
16
+ /**
17
+ * Strategy name (used for registration)
18
+ */
19
+ readonly name: string;
20
+ /**
21
+ * Convert semantic value to Brainy FindParams
22
+ * Uses EXISTING FindParams type from brainy.types.ts
23
+ */
24
+ toQuery(value: any, subpath?: string): FindParams;
25
+ /**
26
+ * Resolve semantic value to entity IDs
27
+ * Uses REAL Brainy.find() method
28
+ *
29
+ * @param brain - REAL Brainy instance
30
+ * @param vfs - REAL VirtualFileSystem instance
31
+ * @param value - The semantic value to resolve
32
+ * @returns Array of entity IDs that match
33
+ */
34
+ resolve(brain: Brainy, vfs: VirtualFileSystem, value: any): Promise<string[]>;
35
+ /**
36
+ * List all entities in this dimension
37
+ * Optional - not all strategies need to implement
38
+ *
39
+ * @param brain - REAL Brainy instance
40
+ * @param vfs - REAL VirtualFileSystem instance
41
+ * @param limit - Max results to return
42
+ */
43
+ list?(brain: Brainy, vfs: VirtualFileSystem, limit?: number): Promise<VFSEntity[]>;
44
+ }
45
+ /**
46
+ * Base class for projection strategies with common utilities
47
+ */
48
+ export declare abstract class BaseProjectionStrategy implements ProjectionStrategy {
49
+ abstract readonly name: string;
50
+ abstract toQuery(value: any, subpath?: string): FindParams;
51
+ abstract resolve(brain: Brainy, vfs: VirtualFileSystem, value: any): Promise<string[]>;
52
+ /**
53
+ * Convert Brainy Results to entity IDs
54
+ * Helper method for subclasses
55
+ */
56
+ protected extractIds(results: Array<{
57
+ id: string;
58
+ }>): string[];
59
+ /**
60
+ * Verify that an entity is a file (not directory)
61
+ * Uses REAL Brainy.get() method
62
+ */
63
+ protected isFile(brain: Brainy, entityId: string): Promise<boolean>;
64
+ /**
65
+ * Filter entity IDs to only include files
66
+ * Uses REAL Brainy.get() for each entity
67
+ */
68
+ protected filterFiles(brain: Brainy, entityIds: string[]): Promise<string[]>;
69
+ }