**feat(utils): add type utility functions and examples for runtime type management**

- Introduced `getNounTypes`, `getVerbTypes`, `getNounTypeMap`, and `getVerbTypeMap` utilities for managing noun and verb types at runtime.
- Added comprehensive unit tests (`type-utils.test.ts`) to ensure correctness of type utility functions.
- Created new example files (`type-utils-example.js`, `type-utils-example.ts`) to demonstrate the use of type utilities in JavaScript and TypeScript environments.
- Updated `README.md` with detailed documentation and usage examples for the new type utilities.
- Enhanced `index.ts` to export the new utility functions, making them accessible throughout the library.

**Purpose**: Facilitate easy access, validation, and manipulation of noun and verb types in client applications, providing better runtime type management.
This commit is contained in:
David Snelling 2025-07-31 14:24:16 -07:00
parent 927dc94edb
commit 17bd7ab42d
6 changed files with 392 additions and 1 deletions

View file

@ -399,6 +399,45 @@ Connections between nouns (edges in the graph):
- Verbs have types that define the relationship (RelatedTo, Controls, Contains, etc.)
- Verbs can have their own metadata to describe the relationship
### Type Utilities
Brainy provides utility functions to access lists of noun and verb types:
```typescript
import {
NounType,
VerbType,
getNounTypes,
getVerbTypes,
getNounTypeMap,
getVerbTypeMap
} from '@soulcraft/brainy'
// At development time:
// Access specific types directly from the NounType and VerbType objects
console.log(NounType.Person) // 'person'
console.log(VerbType.Contains) // 'contains'
// At runtime:
// Get a list of all noun types
const nounTypes = getNounTypes() // ['person', 'organization', 'location', ...]
// Get a list of all verb types
const verbTypes = getVerbTypes() // ['relatedTo', 'contains', 'partOf', ...]
// Get a map of noun type keys to values
const nounTypeMap = getNounTypeMap() // { Person: 'person', Organization: 'organization', ... }
// Get a map of verb type keys to values
const verbTypeMap = getVerbTypeMap() // { RelatedTo: 'relatedTo', Contains: 'contains', ... }
```
These utility functions make it easy to:
- Get a complete list of available noun and verb types
- Validate user input against valid types
- Create dynamic UI components that display or select from available types
- Map between type keys and their string values
## Command Line Interface
Brainy includes a powerful CLI for managing your data. The CLI is available as a separate package