|
| 1 | +# ObjectStack Data Protocol Examples |
| 2 | + |
| 3 | +This package contains comprehensive examples demonstrating all aspects of the ObjectStack Data Protocol. |
| 4 | + |
| 5 | +## 📚 What's Included |
| 6 | + |
| 7 | +### Core Examples |
| 8 | + |
| 9 | +1. **field.examples.ts** - 36 field type examples |
| 10 | + - All field types from FieldType enum |
| 11 | + - Text, numbers, dates, boolean, select, relationships |
| 12 | + - Media fields (image, file, avatar) |
| 13 | + - Calculated fields (formula, summary, autonumber) |
| 14 | + - Enhanced fields (location, address, code, color, rating, etc.) |
| 15 | + |
| 16 | +2. **object.examples.ts** - 10 complete object definitions |
| 17 | + - Simple and complex objects |
| 18 | + - Objects with capabilities, indexes, search configuration |
| 19 | + - Real-world CRM, e-commerce, and project management examples |
| 20 | + |
| 21 | +3. **query.examples.ts** - 25 query examples |
| 22 | + - Simple and complex queries |
| 23 | + - Filtering, sorting, pagination |
| 24 | + - Aggregations and joins |
| 25 | + - Window functions |
| 26 | + - Real-world business queries |
| 27 | + |
| 28 | +4. **filter.examples.ts** - 27 filter condition examples |
| 29 | + - All filter operators (eq, ne, gt, lt, in, etc.) |
| 30 | + - Logical operators (AND, OR, NOT) |
| 31 | + - String matching (contains, startsWith, endsWith) |
| 32 | + - Complex nested conditions |
| 33 | + - Real-world filtering scenarios |
| 34 | + |
| 35 | +5. **validation.examples.ts** - 20 validation rule examples |
| 36 | + - Script validation |
| 37 | + - Uniqueness constraints |
| 38 | + - State machine validation |
| 39 | + - Format validation |
| 40 | + - Cross-field validation |
| 41 | + - Async validation |
| 42 | + - Conditional validation |
| 43 | + - Custom validation |
| 44 | + |
| 45 | +6. **hook.examples.ts** - 20 lifecycle hook examples |
| 46 | + - Before/after insert, update, delete |
| 47 | + - Read hooks (beforeFind, afterFind) |
| 48 | + - Data enrichment and transformation |
| 49 | + - External system integration |
| 50 | + - Audit trail and notifications |
| 51 | + |
| 52 | +7. **mapping.examples.ts** - 10 ETL mapping examples |
| 53 | + - CSV and JSON imports |
| 54 | + - Data transformations (constant, lookup, map, split, join) |
| 55 | + - Export configurations |
| 56 | + - Complex multi-lookup scenarios |
| 57 | + - Migration use cases |
| 58 | + |
| 59 | +8. **dataset.examples.ts** - 10 seed data examples |
| 60 | + - Reference data (countries, currencies) |
| 61 | + - System configuration |
| 62 | + - Demo and test data |
| 63 | + - Environment-specific datasets |
| 64 | + |
| 65 | +## 🚀 Usage |
| 66 | + |
| 67 | +```typescript |
| 68 | +import { |
| 69 | + SimpleTextField, |
| 70 | + SimpleObject, |
| 71 | + SimpleSelectQuery, |
| 72 | + EqualityFilter, |
| 73 | + RequiredFieldValidation, |
| 74 | + SendNotificationHook, |
| 75 | + SimpleCsvImportMapping, |
| 76 | + CountryDataset, |
| 77 | +} from '@objectstack/example-data'; |
| 78 | +``` |
| 79 | + |
| 80 | +## 🏗️ Building |
| 81 | + |
| 82 | +```bash |
| 83 | +npm run build |
| 84 | +``` |
| 85 | + |
| 86 | +This compiles all TypeScript examples to JavaScript and generates type declarations. |
| 87 | + |
| 88 | +## 📖 Example Structure |
| 89 | + |
| 90 | +Each example follows this pattern: |
| 91 | +- Descriptive constant name (e.g., `SimpleSalesCrmApp`) |
| 92 | +- Comprehensive JSDoc comment explaining the use case |
| 93 | +- Complete, valid example using proper schemas |
| 94 | +- Realistic, practical scenarios (CRM, e-commerce, project management) |
| 95 | + |
| 96 | +## 🎯 Use Cases |
| 97 | + |
| 98 | +These examples are designed for: |
| 99 | +- **Learning**: Understand ObjectStack Data Protocol patterns |
| 100 | +- **Reference**: Copy-paste starting points for your own metadata |
| 101 | +- **Testing**: Validate implementations against standard patterns |
| 102 | +- **Documentation**: Illustrate best practices and conventions |
| 103 | + |
| 104 | +## 📝 Naming Conventions |
| 105 | + |
| 106 | +- **Configuration Keys**: camelCase (e.g., `maxLength`, `referenceFilters`) |
| 107 | +- **Machine Names**: snake_case (e.g., `first_name`, `project_task`) |
| 108 | +- **Example Constants**: PascalCase (e.g., `EmailField`, `ContactObject`) |
| 109 | + |
| 110 | +## 🔗 Related |
| 111 | + |
| 112 | +- [ObjectStack Spec](../../../packages/spec) - Core schema definitions |
| 113 | +- [UI Examples](../../ui/metadata-examples) - UI Protocol examples |
0 commit comments