Skip to content

Commit 589dc6e

Browse files
committed
Refactor ObjectQLPlugin and update imports for better structure
1 parent 27be77f commit 589dc6e

6 files changed

Lines changed: 45 additions & 83 deletions

File tree

examples/host/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin, ObjectQL } from '@objectstack/runtime';
1+
import { ObjectKernel, DriverPlugin, AppManifestPlugin, ObjectQL } from '@objectstack/runtime';
22
import { InMemoryDriver } from '@objectstack/driver-memory';
3+
import { ObjectQLPlugin } from '@objectstack/objectql';
34
import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
45

56
import CrmApp from '@objectstack/example-crm/objectstack.config';

packages/objectql/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"test": "vitest"
1010
},
1111
"dependencies": {
12-
"@objectstack/spec": "workspace:*"
12+
"@objectstack/spec": "workspace:*",
13+
"@objectstack/types": "workspace:*"
1314
},
1415
"devDependencies": {
1516
"typescript": "^5.0.0",

packages/objectql/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,4 @@ export class ObjectQL implements IDataEngine {
402402
return hookContext.result;
403403
}
404404
}
405+
export * from './plugin';

packages/objectql/src/plugin.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { ObjectQL } from './index';
2+
3+
// Minimal Context interface to avoid circular dependency on @objectstack/runtime
4+
export interface PluginContext {
5+
registerService(name: string, service: any): void;
6+
logger: Console;
7+
[key: string]: any;
8+
}
9+
10+
export class ObjectQLPlugin {
11+
name = 'com.objectstack.engine.objectql';
12+
type = 'objectql' as const;
13+
version = '1.0.0';
14+
15+
private ql: ObjectQL | undefined;
16+
private hostContext?: Record<string, any>;
17+
18+
constructor(ql?: ObjectQL, hostContext?: Record<string, any>) {
19+
if (ql) {
20+
this.ql = ql;
21+
} else {
22+
this.hostContext = hostContext;
23+
// Lazily created in init
24+
}
25+
}
26+
27+
async init(ctx: PluginContext) {
28+
if (!this.ql) {
29+
this.ql = new ObjectQL(this.hostContext);
30+
}
31+
32+
ctx.registerService('objectql', this.ql);
33+
if(ctx.logger) ctx.logger.log(`[ObjectQLPlugin] ObjectQL engine registered as service`);
34+
}
35+
36+
async start(ctx: PluginContext) {
37+
if(ctx.logger) ctx.logger.log(`[ObjectQLPlugin] ObjectQL engine initialized`);
38+
}
39+
}

packages/runtime/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export { ObjectQL, SchemaRegistry } from '@objectstack/objectql';
55
export { ObjectKernel } from './mini-kernel.js';
66

77
// Export Plugins
8-
export { ObjectQLPlugin } from './objectql-plugin.js';
8+
export { ObjectQLPlugin } from '@objectstack/objectql';
99
export { DriverPlugin } from './driver-plugin.js';
1010
export { AppManifestPlugin } from './app-manifest-plugin.js';
1111

packages/runtime/src/objectql-plugin.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)