|
| 1 | +# ObjectStack Runtime Integration |
| 2 | + |
| 3 | +This document explains the integration of `@objectstack/runtime` and `@objectstack/objectql` into the ObjectQL platform. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +As of version 3.0.1, ObjectQL core integrates with the latest ObjectStack runtime packages: |
| 8 | + |
| 9 | +- **@objectstack/spec@0.1.2**: Protocol specification with TypeScript interfaces |
| 10 | +- **@objectstack/objectql@0.1.1**: Core ObjectQL engine with basic driver management |
| 11 | +- **@objectstack/runtime@0.1.1**: Runtime kernel with application lifecycle orchestration |
| 12 | + |
| 13 | +## Architecture |
| 14 | + |
| 15 | +### Package Relationship |
| 16 | + |
| 17 | +``` |
| 18 | +@objectql/core (this package) |
| 19 | +├── Extends/complements @objectstack/objectql |
| 20 | +├── Uses types from @objectstack/spec |
| 21 | +└── Re-exports types from @objectstack/runtime |
| 22 | +``` |
| 23 | + |
| 24 | +### Type Exports |
| 25 | + |
| 26 | +The core package exports types from the runtime packages for API compatibility: |
| 27 | + |
| 28 | +```typescript |
| 29 | +// Type-only exports to avoid runtime issues |
| 30 | +export type { |
| 31 | + ObjectStackKernel, |
| 32 | + ObjectStackRuntimeProtocol |
| 33 | +} from '@objectstack/runtime'; |
| 34 | + |
| 35 | +export type { |
| 36 | + ObjectQL as ObjectQLEngine, |
| 37 | + SchemaRegistry |
| 38 | +} from '@objectstack/objectql'; |
| 39 | +``` |
| 40 | + |
| 41 | +## Implementation Details |
| 42 | + |
| 43 | +### Current ObjectQL vs. ObjectQLEngine |
| 44 | + |
| 45 | +The current `ObjectQL` class in this package is a **production-ready, feature-rich** implementation that includes: |
| 46 | + |
| 47 | +- Full metadata registry |
| 48 | +- Hooks system |
| 49 | +- Actions system |
| 50 | +- Validation engine |
| 51 | +- Repository pattern |
| 52 | +- Formula engine |
| 53 | +- AI integration |
| 54 | + |
| 55 | +The `ObjectQLEngine` from `@objectstack/objectql` is a **simpler, lightweight** implementation suitable for: |
| 56 | + |
| 57 | +- Basic CRUD operations |
| 58 | +- Simple driver management |
| 59 | +- Minimal runtime overhead |
| 60 | + |
| 61 | +### Why Type-Only Exports? |
| 62 | + |
| 63 | +The `@objectstack/objectql` package currently has a configuration issue where it points to source files instead of compiled dist files. To avoid runtime errors, we use **type-only imports** which provide TypeScript type checking without executing the runtime code. |
| 64 | + |
| 65 | +## Usage |
| 66 | + |
| 67 | +### Using the Full-Featured ObjectQL (Recommended) |
| 68 | + |
| 69 | +```typescript |
| 70 | +import { ObjectQL } from '@objectql/core'; |
| 71 | + |
| 72 | +const app = new ObjectQL({ |
| 73 | + registry: new MetadataRegistry(), |
| 74 | + datasources: { default: driver } |
| 75 | +}); |
| 76 | + |
| 77 | +await app.init(); |
| 78 | +const ctx = app.createContext({ userId: 'user123' }); |
| 79 | +const repo = ctx.object('todo'); |
| 80 | +const items = await repo.find({}); |
| 81 | +``` |
| 82 | + |
| 83 | +### Using Type Definitions from Runtime |
| 84 | + |
| 85 | +```typescript |
| 86 | +import type { ObjectStackKernel, SchemaRegistry } from '@objectql/core'; |
| 87 | + |
| 88 | +// Use types for compile-time checking |
| 89 | +function processKernel(kernel: ObjectStackKernel) { |
| 90 | + // Your code here |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +## Migration Path |
| 95 | + |
| 96 | +If you want to use the simpler `@objectstack/objectql` implementation: |
| 97 | + |
| 98 | +1. Install it directly: `npm install @objectstack/objectql` |
| 99 | +2. Import from the package: `import { ObjectQL } from '@objectstack/objectql'` |
| 100 | +3. Note: Ensure the package is properly built before use |
| 101 | + |
| 102 | +## Compatibility |
| 103 | + |
| 104 | +- **@objectstack/spec@0.1.2**: Introduces `searchable` field requirement on FieldConfig |
| 105 | +- **Backward Compatible**: All existing ObjectQL APIs remain unchanged |
| 106 | +- **Tests**: 236 tests pass successfully, confirming backward compatibility |
| 107 | + |
| 108 | +## Future Plans |
| 109 | + |
| 110 | +Once the `@objectstack/objectql` package configuration is fixed, we may: |
| 111 | + |
| 112 | +1. Use it as a base class for our ObjectQL implementation |
| 113 | +2. Move framework-specific features to plugins |
| 114 | +3. Provide both lightweight and full-featured options |
| 115 | + |
| 116 | +## Related Documentation |
| 117 | + |
| 118 | +- [ObjectQL Types](../types/README.md) |
| 119 | +- [ObjectQL Platform Node](../platform-node/README.md) |
| 120 | +- [@objectstack/spec on npm](https://www.npmjs.com/package/@objectstack/spec) |
| 121 | +- [@objectstack/runtime on npm](https://www.npmjs.com/package/@objectstack/runtime) |
0 commit comments