|
| 1 | +# @objectstack/spec |
| 2 | + |
| 3 | +[](https://www.typescriptlang.org/) |
| 4 | +[](https://opensource.org/licenses/MIT) |
| 5 | + |
| 6 | +> ObjectStack Protocol & Specification - The Constitution of the ObjectStack Ecosystem |
| 7 | +
|
| 8 | +## 📜 Overview |
| 9 | + |
| 10 | +This package defines the **core interfaces, schemas, and conventions** for the ObjectStack ecosystem. It serves as the "Constitution" - the shared language that ObjectOS, ObjectStudio, ObjectCloud, and all third-party plugins use to communicate. |
| 11 | + |
| 12 | +**Guiding Principle:** *"Strict Types, No Logic"* |
| 13 | + |
| 14 | +This package contains: |
| 15 | +- ✅ TypeScript Interfaces (Shared types) |
| 16 | +- ✅ Zod Schemas (Validation rules with type inference) |
| 17 | +- ✅ Constants (Convention configurations) |
| 18 | + |
| 19 | +This package does NOT contain: |
| 20 | +- ❌ Database connections |
| 21 | +- ❌ UI components |
| 22 | +- ❌ Runtime business logic |
| 23 | + |
| 24 | +## 🚀 Installation |
| 25 | + |
| 26 | +```bash |
| 27 | +npm install @objectstack/spec |
| 28 | +``` |
| 29 | + |
| 30 | +## 📦 What's Inside |
| 31 | + |
| 32 | +### 1. Manifest Schema (`ManifestSchema`) |
| 33 | + |
| 34 | +Defines the structure of a package configuration file. All packages (apps, plugins, drivers, modules) must conform to this schema. |
| 35 | + |
| 36 | +```typescript |
| 37 | +import { ManifestSchema, type ObjectStackManifest } from '@objectstack/spec'; |
| 38 | + |
| 39 | +// Validate a manifest |
| 40 | +const manifest: ObjectStackManifest = { |
| 41 | + id: 'com.example.myapp', |
| 42 | + version: '1.0.0', |
| 43 | + type: 'plugin', |
| 44 | + name: 'My App', |
| 45 | + permissions: ['system.user.read'], |
| 46 | + menus: [ |
| 47 | + { label: 'Dashboard', path: '/dashboard', icon: 'home' } |
| 48 | + ] |
| 49 | +}; |
| 50 | + |
| 51 | +// Validate with Zod |
| 52 | +ManifestSchema.parse(manifest); |
| 53 | +``` |
| 54 | + |
| 55 | +### 2. Plugin Runtime Interface (`ObjectStackPlugin`) |
| 56 | + |
| 57 | +Defines the contract that every plugin must implement to be loaded by ObjectOS. |
| 58 | + |
| 59 | +```typescript |
| 60 | +import { ObjectStackPlugin, PluginContext } from '@objectstack/spec'; |
| 61 | + |
| 62 | +export default function createPlugin(): ObjectStackPlugin { |
| 63 | + return { |
| 64 | + async onInstall(ctx: PluginContext) { |
| 65 | + ctx.logger.info('Plugin installed'); |
| 66 | + }, |
| 67 | + |
| 68 | + async onEnable(ctx: PluginContext) { |
| 69 | + ctx.logger.info('Plugin enabled'); |
| 70 | + }, |
| 71 | + |
| 72 | + async onDisable(ctx: PluginContext) { |
| 73 | + ctx.logger.info('Plugin disabled'); |
| 74 | + } |
| 75 | + }; |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +### 3. Directory Conventions (`PKG_CONVENTIONS`) |
| 80 | + |
| 81 | +Defines the "Law of Location" - where things must be in ObjectStack packages. |
| 82 | + |
| 83 | +```typescript |
| 84 | +import { PKG_CONVENTIONS } from '@objectstack/spec'; |
| 85 | + |
| 86 | +console.log(PKG_CONVENTIONS.DIRS.SCHEMA); // 'src/schemas' |
| 87 | +console.log(PKG_CONVENTIONS.DIRS.TRIGGERS); // 'src/triggers' |
| 88 | +console.log(PKG_CONVENTIONS.FILES.MANIFEST); // 'objectstack.config.ts' |
| 89 | +``` |
| 90 | + |
| 91 | +## 📚 API Reference |
| 92 | + |
| 93 | +### Schemas |
| 94 | + |
| 95 | +- `ManifestSchema` - Zod schema for package manifests |
| 96 | +- `MenuItemSchema` - Zod schema for menu items |
| 97 | +- `ObjectStackManifest` - TypeScript type for manifests |
| 98 | +- `MenuItem` - TypeScript type for menu items |
| 99 | + |
| 100 | +### Types |
| 101 | + |
| 102 | +- `ObjectStackPlugin` - Plugin interface with lifecycle methods |
| 103 | +- `PluginContext` - Context provided to plugin methods |
| 104 | +- `PluginFactory` - Plugin factory function type |
| 105 | +- `PluginLogger` - Logger interface |
| 106 | +- `ObjectQLClient` - Database client interface |
| 107 | +- `ObjectOSKernel` - OS kernel interface |
| 108 | + |
| 109 | +### Constants |
| 110 | + |
| 111 | +- `PKG_CONVENTIONS` - Directory and file conventions |
| 112 | +- `PackageDirectory` - Type for package directories |
| 113 | +- `PackageFile` - Type for package files |
| 114 | + |
| 115 | +## 🏗️ Development |
| 116 | + |
| 117 | +```bash |
| 118 | +# Install dependencies |
| 119 | +npm install |
| 120 | + |
| 121 | +# Build the project |
| 122 | +npm run build |
| 123 | + |
| 124 | +# Watch mode for development |
| 125 | +npm run dev |
| 126 | + |
| 127 | +# Clean build artifacts |
| 128 | +npm run clean |
| 129 | +``` |
| 130 | + |
| 131 | +## 📄 License |
1 | 132 | # ObjectStack Specification |
2 | 133 |
|
3 | 134 | 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. |
|
0 commit comments