@objectql/core 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +17 -3
  2. package/README.md +3 -3
  3. package/dist/app.d.ts +1 -1
  4. package/dist/app.js +1 -1
  5. package/dist/app.js.map +1 -1
  6. package/dist/formula-plugin.d.ts +1 -1
  7. package/dist/index.d.ts +5 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/plugin.d.ts +2 -2
  10. package/dist/plugin.js +40 -3
  11. package/dist/plugin.js.map +1 -1
  12. package/dist/query/filter-translator.d.ts +3 -1
  13. package/dist/query/filter-translator.js.map +1 -1
  14. package/dist/query/query-analyzer.d.ts +3 -1
  15. package/dist/query/query-analyzer.js.map +1 -1
  16. package/dist/query/query-builder.d.ts +3 -1
  17. package/dist/query/query-builder.js.map +1 -1
  18. package/dist/query/query-service.d.ts +3 -1
  19. package/dist/query/query-service.js.map +1 -1
  20. package/dist/repository.js +19 -1
  21. package/dist/repository.js.map +1 -1
  22. package/dist/validator-plugin.d.ts +1 -1
  23. package/jest.config.js +1 -1
  24. package/package.json +4 -5
  25. package/src/app.ts +3 -3
  26. package/src/formula-plugin.ts +1 -1
  27. package/src/index.ts +5 -2
  28. package/src/plugin.ts +50 -5
  29. package/src/query/filter-translator.ts +2 -1
  30. package/src/query/query-analyzer.ts +3 -1
  31. package/src/query/query-builder.ts +2 -1
  32. package/src/query/query-service.ts +2 -1
  33. package/src/repository.ts +22 -3
  34. package/src/validator-plugin.ts +1 -1
  35. package/test/__mocks__/@objectstack/runtime.ts +1 -1
  36. package/test/formula-plugin.test.ts +1 -1
  37. package/test/validator-plugin.test.ts +1 -1
  38. package/tsconfig.json +0 -1
  39. package/tsconfig.tsbuildinfo +1 -1
  40. package/IMPLEMENTATION_STATUS.md +0 -364
  41. package/RUNTIME_INTEGRATION.md +0 -391
@@ -1,391 +0,0 @@
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 4.0.0, ObjectQL core uses the ObjectStack runtime packages with plugin architecture:
8
-
9
- - **@objectstack/spec@0.2.0**: Protocol specification with standard `DriverInterface`
10
- - **@objectstack/objectql@0.2.0**: Core ObjectQL engine with driver management
11
- - **@objectstack/runtime@0.2.0**: Runtime kernel with application lifecycle orchestration and plugin system
12
-
13
- ## Architecture
14
-
15
- ### Package Relationship
16
-
17
- ```
18
- @objectql/core (this package)
19
- ├── Wraps ObjectStackKernel from @objectstack/runtime
20
- ├── Implements ObjectQLPlugin for enhanced features
21
- ├── Uses @objectstack/objectql for driver management
22
- ├── Natively uses @objectstack/spec.DriverInterface (no wrapper)
23
- └── Re-exports types from @objectstack/runtime
24
- ```
25
-
26
- ### Plugin Architecture (v4.0.0)
27
-
28
- **Breaking Change (v4.0.0):** The core package now **wraps `ObjectStackKernel`** and uses a plugin architecture:
29
-
30
- ```typescript
31
- import { ObjectQL, ObjectQLPlugin } from '@objectql/core';
32
- import type { DriverInterface } from '@objectstack/spec';
33
-
34
- // ObjectQL now wraps ObjectStackKernel internally
35
- const app = new ObjectQL({
36
- datasources: {
37
- default: myDriver // Must be DriverInterface
38
- }
39
- });
40
-
41
- // Access the kernel if needed
42
- const kernel = app.getKernel();
43
-
44
- await app.init(); // This calls kernel.start() internally
45
- ```
46
-
47
- ### ObjectQLPlugin
48
-
49
- The new `ObjectQLPlugin` class implements the `RuntimePlugin` interface from `@objectstack/runtime`:
50
-
51
- ```typescript
52
- import { ObjectQLPlugin, ObjectQLPluginConfig } from '@objectql/core';
53
-
54
- // Configure the plugin
55
- const plugin = new ObjectQLPlugin({
56
- enableRepository: true,
57
- enableValidator: true,
58
- enableFormulas: true,
59
- enableAI: true
60
- });
61
-
62
- // The plugin is automatically registered when you create an ObjectQL instance
63
- const app = new ObjectQL({ datasources: {} });
64
- ```
65
-
66
- ### Type Exports
67
-
68
- The core package exports types from the ObjectStack packages:
69
-
70
- ```typescript
71
- // Driver development types
72
- export type {
73
- DriverInterface,
74
- DriverOptions,
75
- QueryAST
76
- } from '@objectstack/spec';
77
-
78
- // Runtime integration types
79
- export type {
80
- ObjectStackKernel,
81
- ObjectStackRuntimeProtocol
82
- } from '@objectstack/runtime';
83
-
84
- export type {
85
- ObjectQL as ObjectQLEngine,
86
- SchemaRegistry
87
- } from '@objectstack/objectql';
88
- ```
89
-
90
- ## Implementation Details
91
-
92
- ### Current ObjectQL vs. ObjectQLEngine
93
-
94
- The current `ObjectQL` class in this package is a **production-ready, feature-rich** implementation that includes:
95
-
96
- - Full metadata registry
97
- - Hooks system
98
- - Actions system
99
- - Validation engine
100
- - Repository pattern
101
- - Formula engine
102
- - AI integration
103
- - **Wraps ObjectStackKernel for plugin architecture**
104
- - **Native driver management via @objectstack/objectql**
105
-
106
- The `ObjectQLEngine` from `@objectstack/objectql` is a **simpler, lightweight** implementation suitable for:
107
-
108
- - Basic CRUD operations
109
- - Simple driver management
110
- - Minimal runtime overhead
111
-
112
- ### Kernel Integration
113
-
114
- ObjectQL now wraps the `ObjectStackKernel` to provide plugin architecture and lifecycle management:
115
-
116
- ```typescript
117
- // In @objectql/core
118
- import { ObjectStackKernel } from '@objectstack/runtime';
119
- import { ObjectQLPlugin } from './plugin';
120
-
121
- export class ObjectQL implements IObjectQL {
122
- private kernel: ObjectStackKernel;
123
- private kernelPlugins: any[] = [];
124
-
125
- constructor(config: ObjectQLConfig) {
126
- // Add the ObjectQL plugin to provide enhanced features
127
- this.kernelPlugins.push(new ObjectQLPlugin());
128
-
129
- // Create the kernel instance
130
- this.kernel = new ObjectStackKernel(this.kernelPlugins);
131
- }
132
-
133
- async init() {
134
- console.log('[ObjectQL] Initializing with ObjectStackKernel...');
135
-
136
- // Start the kernel first - this will install and start all plugins
137
- await this.kernel.start();
138
-
139
- // Continue with legacy initialization...
140
- }
141
-
142
- /**
143
- * Get the underlying ObjectStackKernel instance
144
- * for advanced usage scenarios
145
- */
146
- getKernel(): ObjectStackKernel {
147
- return this.kernel;
148
- }
149
- }
150
- ```
151
-
152
- ### Driver Management (No Compatibility Layer)
153
-
154
- ObjectQL now directly uses drivers conforming to `@objectstack/spec.DriverInterface`:
155
-
156
- ```typescript
157
- // In @objectql/core
158
- import { DriverInterface } from '@objectstack/spec';
159
-
160
- private datasources: Record<string, DriverInterface> = {};
161
- private stackEngine: ObjectStackEngine;
162
-
163
- constructor(config: ObjectQLConfig) {
164
- this.stackEngine = new ObjectStackEngine({});
165
-
166
- // Register drivers directly (no wrapping)
167
- for (const [name, driver] of Object.entries(config.datasources)) {
168
- this.stackEngine.registerDriver(driver, name === 'default');
169
- }
170
- }
171
- ```
172
-
173
- ### Simplified Lifecycle
174
-
175
- The ObjectStack engine handles all driver lifecycle management:
176
-
177
- ```typescript
178
- async close() {
179
- // ObjectStack engine manages all driver disconnect logic
180
- await this.stackEngine.destroy();
181
- }
182
- ```
183
-
184
- ### Custom Driver Development
185
-
186
- To build custom drivers for ObjectStack, implement `DriverInterface` from `@objectstack/spec`:
187
-
188
- ```typescript
189
- import { DriverInterface, QueryAST } from '@objectstack/spec';
190
-
191
- export class MyCustomDriver implements DriverInterface {
192
- name = 'MyDriver';
193
- version = '1.0.0';
194
-
195
- async connect() {
196
- // Initialize connection
197
- }
198
-
199
- async disconnect() {
200
- // Close connection
201
- }
202
-
203
- async find(object: string, query: QueryAST, options?: any) {
204
- // Query implementation
205
- return [];
206
- }
207
-
208
- async create(object: string, data: any, options?: any) {
209
- // Create implementation
210
- return data;
211
- }
212
-
213
- async update(object: string, id: string, data: any, options?: any) {
214
- // Update implementation
215
- return data;
216
- }
217
-
218
- async delete(object: string, id: string, options?: any) {
219
- // Delete implementation
220
- }
221
- }
222
- ```
223
-
224
- Register with ObjectQL:
225
-
226
- ```typescript
227
- import { ObjectQL } from '@objectql/core';
228
- import { MyCustomDriver } from './my-driver';
229
-
230
- const app = new ObjectQL({
231
- datasources: {
232
- default: new MyCustomDriver()
233
- }
234
- });
235
-
236
- // Or register dynamically
237
- app.registerDriver('mydb', new MyCustomDriver(), false);
238
- ```
239
-
240
- ## Breaking Changes
241
-
242
- ### v4.0.0: Plugin Architecture
243
-
244
- **What Changed:**
245
- - `ObjectQL` now wraps `ObjectStackKernel` from `@objectstack/runtime`
246
- - New `ObjectQLPlugin` class implements `RuntimePlugin` interface
247
- - Initialization process now calls `kernel.start()` which installs and starts all plugins
248
- - Dependencies updated to `@objectstack/*@0.2.0`
249
- - New `getKernel()` method provides access to the underlying kernel
250
- - **Removed legacy plugin support** - all plugins must now implement the `RuntimePlugin` interface
251
-
252
- **Migration Guide:**
253
-
254
- The ObjectQL API remains the same:
255
- ```typescript
256
- import { ObjectQL } from '@objectql/core';
257
- import { MyDriver } from './my-driver';
258
-
259
- const app = new ObjectQL({
260
- datasources: {
261
- default: new MyDriver()
262
- }
263
- });
264
-
265
- await app.init(); // Calls kernel.start() internally
266
- ```
267
-
268
- Access the kernel for advanced use cases:
269
- ```typescript
270
- const kernel = app.getKernel(); // Must call after init()
271
- ```
272
-
273
- **Plugin Migration:**
274
-
275
- Old plugins with `onEnable` hook are no longer supported. Migrate to `RuntimePlugin`:
276
-
277
- ```typescript
278
- // Old (no longer supported)
279
- const plugin = {
280
- id: 'my-plugin',
281
- onEnable: async (context) => {
282
- // initialization logic
283
- }
284
- };
285
-
286
- // New (required)
287
- import type { RuntimePlugin, RuntimeContext } from '@objectstack/runtime';
288
-
289
- class MyPlugin implements RuntimePlugin {
290
- name = 'my-plugin';
291
-
292
- async install(ctx: RuntimeContext): Promise<void> {
293
- // installation logic
294
- }
295
-
296
- async onStart(ctx: RuntimeContext): Promise<void> {
297
- // startup logic
298
- }
299
- }
300
-
301
- const plugin = new MyPlugin();
302
- ```
303
-
304
- ### v3.0.1: Native DriverInterface Adoption
305
-
306
- **What Changed:**
307
- - `ObjectQLConfig.datasources` now requires `Record<string, DriverInterface>` (from `@objectstack/spec`)
308
- - Removed compatibility wrapper for old `Driver` type
309
- - `app.datasource()` now returns `DriverInterface`
310
- - Driver lifecycle is fully managed by ObjectStack engine
311
-
312
- **Migration Guide:**
313
-
314
- Old code (deprecated):
315
- ```typescript
316
- import { Driver } from '@objectql/types';
317
-
318
- class MyDriver implements Driver {
319
- // Old Driver interface
320
- }
321
- ```
322
-
323
- New code (required):
324
- ```typescript
325
- import { DriverInterface, QueryAST } from '@objectstack/spec';
326
-
327
- class MyDriver implements DriverInterface {
328
- name = 'MyDriver';
329
- version = '1.0.0';
330
-
331
- async connect() { }
332
- async disconnect() { }
333
- async find(object: string, query: QueryAST, options?: any) { }
334
- async create(object: string, data: any, options?: any) { }
335
- async update(object: string, id: string, data: any, options?: any) { }
336
- async delete(object: string, id: string, options?: any) { }
337
- }
338
- ```
339
-
340
- ## Usage
341
-
342
- ### Using the Full-Featured ObjectQL (Recommended)
343
-
344
- ```typescript
345
- import { ObjectQL } from '@objectql/core';
346
- import { MemoryDriver } from '@objectql/driver-memory';
347
-
348
- const app = new ObjectQL({
349
- datasources: { default: new MemoryDriver() }
350
- });
351
-
352
- await app.init();
353
- const ctx = app.createContext({ userId: 'user123' });
354
- const repo = ctx.object('todo');
355
- const items = await repo.find({});
356
- ```
357
-
358
- ### Using Type Definitions
359
-
360
- ```typescript
361
- import type { DriverInterface, QueryAST } from '@objectql/core';
362
-
363
- // Use types for compile-time checking (type-only import)
364
- function validateQuery(query: QueryAST): boolean {
365
- return query.object !== undefined;
366
- }
367
- ```
368
-
369
- ## Compatibility
370
-
371
- - **@objectstack/spec@0.1.2**: Standard `DriverInterface` protocol
372
- - **@objectstack/objectql@0.1.1**: Provides driver registration and lifecycle management
373
- - **Breaking Change**: Old `Driver` type from `@objectql/types` is no longer supported
374
- - **Tests**: All tests updated to use `DriverInterface`
375
-
376
- ## Future Plans
377
-
378
- The native integration with `@objectstack/objectql` enables:
379
-
380
- 1. Standardized driver interface across the ObjectStack ecosystem
381
- 2. Plugin system for extending driver capabilities
382
- 3. Unified driver management across multiple packages
383
- 4. Driver marketplace and discovery
384
-
385
- ## Related Documentation
386
-
387
- - [ObjectQL Types](../types/README.md)
388
- - [ObjectQL Platform Node](../platform-node/README.md)
389
- - [@objectstack/spec on npm](https://www.npmjs.com/package/@objectstack/spec)
390
- - [@objectstack/runtime on npm](https://www.npmjs.com/package/@objectstack/runtime)
391
- - [@objectstack/objectql on npm](https://www.npmjs.com/package/@objectstack/objectql)