|
1 | | -# spec |
| 1 | +# ObjectStack Specification |
| 2 | + |
| 3 | +The ObjectStack Protocol & Specification repository defines the core type definitions and interfaces for the ObjectStack ecosystem. This repository serves as the "Constitution" of the system, providing the contract between backend (ObjectQL) parsers and frontend (ObjectUI) renderers. |
| 4 | + |
| 5 | +## Purpose |
| 6 | + |
| 7 | +This repository contains: |
| 8 | +- **TypeScript Interfaces**: Shared types for the entire ObjectStack ecosystem |
| 9 | +- **No Logic**: Only type definitions, no runtime code or business logic |
| 10 | +- **Universal Compatibility**: Works in Node.js, Browser, and Electron environments |
| 11 | + |
| 12 | +## Metamodel Interfaces |
| 13 | + |
| 14 | +The metamodel defines the structure for describing data models in ObjectStack: |
| 15 | + |
| 16 | +### Core Interfaces |
| 17 | + |
| 18 | +#### `FieldType` |
| 19 | +Defines the available field data types: |
| 20 | +- Text types: `text`, `textarea`, `email`, `url` |
| 21 | +- Numeric types: `number`, `currency`, `percentage` |
| 22 | +- Date/Time types: `date`, `datetime` |
| 23 | +- Relation types: `lookup` |
| 24 | +- Selection types: `select`, `multiselect` |
| 25 | +- Special types: `boolean`, `json`, `file`, `image` |
| 26 | + |
| 27 | +#### `ObjectField` |
| 28 | +Represents a field definition within an entity: |
| 29 | +```typescript |
| 30 | +interface ObjectField { |
| 31 | + name: string; // Field identifier |
| 32 | + label: string; // Display label |
| 33 | + type: FieldType; // Data type |
| 34 | + required?: boolean; // Validation |
| 35 | + unique?: boolean; // Constraint |
| 36 | + lookupEntity?: string; // For lookup fields |
| 37 | + // ... and more options |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +#### `ObjectEntity` |
| 42 | +Represents a complete entity (data model) definition: |
| 43 | +```typescript |
| 44 | +interface ObjectEntity { |
| 45 | + name: string; // Entity identifier |
| 46 | + label: string; // Singular display label |
| 47 | + pluralLabel: string; // Plural display label |
| 48 | + fields: ObjectField[]; // Field definitions |
| 49 | + primaryKey?: string; // Primary key field |
| 50 | + displayField?: string; // Display field for lookups |
| 51 | + // ... and more options |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +#### `ObjectView` |
| 56 | +Represents a view configuration for presenting entity data: |
| 57 | +```typescript |
| 58 | +interface ObjectView { |
| 59 | + name: string; // View identifier |
| 60 | + label: string; // Display label |
| 61 | + entityName: string; // Target entity |
| 62 | + type: ViewType; // Presentation type (list, form, detail, etc.) |
| 63 | + fields?: string[]; // Fields to display |
| 64 | + columns?: ViewColumn[]; // Column configuration |
| 65 | + filters?: ViewFilter[]; // Default filters |
| 66 | + sort?: ViewSort[]; // Default sort order |
| 67 | + // ... and more options |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +## Usage |
| 72 | + |
| 73 | +### Installation |
| 74 | + |
| 75 | +```bash |
| 76 | +npm install @objectstack/spec |
| 77 | +``` |
| 78 | + |
| 79 | +### Importing Types |
| 80 | + |
| 81 | +```typescript |
| 82 | +// Import all metamodel types |
| 83 | +import { ObjectEntity, ObjectField, ObjectView, FieldType } from '@objectstack/spec'; |
| 84 | + |
| 85 | +// Or import specific types |
| 86 | +import type { ObjectEntity } from '@objectstack/spec'; |
| 87 | +``` |
| 88 | + |
| 89 | +### Example: Defining an Entity |
| 90 | + |
| 91 | +```typescript |
| 92 | +import { ObjectEntity, ObjectField } from '@objectstack/spec'; |
| 93 | + |
| 94 | +const userEntity: ObjectEntity = { |
| 95 | + name: 'User', |
| 96 | + label: 'User', |
| 97 | + pluralLabel: 'Users', |
| 98 | + description: 'System user account', |
| 99 | + fields: [ |
| 100 | + { |
| 101 | + name: 'id', |
| 102 | + label: 'ID', |
| 103 | + type: 'text', |
| 104 | + required: true, |
| 105 | + readonly: true |
| 106 | + }, |
| 107 | + { |
| 108 | + name: 'email', |
| 109 | + label: 'Email', |
| 110 | + type: 'email', |
| 111 | + required: true, |
| 112 | + unique: true |
| 113 | + }, |
| 114 | + { |
| 115 | + name: 'name', |
| 116 | + label: 'Full Name', |
| 117 | + type: 'text', |
| 118 | + required: true |
| 119 | + }, |
| 120 | + { |
| 121 | + name: 'role', |
| 122 | + label: 'Role', |
| 123 | + type: 'select', |
| 124 | + required: true, |
| 125 | + options: [ |
| 126 | + { value: 'admin', label: 'Administrator' }, |
| 127 | + { value: 'user', label: 'User' } |
| 128 | + ] |
| 129 | + } |
| 130 | + ], |
| 131 | + primaryKey: 'id', |
| 132 | + displayField: 'name' |
| 133 | +}; |
| 134 | +``` |
| 135 | + |
| 136 | +## Building |
| 137 | + |
| 138 | +```bash |
| 139 | +npm install |
| 140 | +npm run build |
| 141 | +``` |
| 142 | + |
| 143 | +This will compile TypeScript files to JavaScript and generate type declarations in the `dist/` directory. |
| 144 | + |
| 145 | +## Philosophy |
| 146 | + |
| 147 | +Following the ObjectStack Protocol: |
| 148 | +- **Strict Types, No Logic**: This repository contains only type definitions |
| 149 | +- **Documentation as Code**: Every interface property has TSDoc comments for IntelliSense |
| 150 | +- **Universal Compatibility**: Pure TypeScript with no platform-specific dependencies |
| 151 | + |
| 152 | +## License |
| 153 | + |
| 154 | +MIT |
0 commit comments