-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplugin.ts
More file actions
62 lines (52 loc) · 1.93 KB
/
Copy pathplugin.ts
File metadata and controls
62 lines (52 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { ObjectQL } from './engine.js';
import { ObjectStackProtocolImplementation } from './protocol.js';
import { Plugin, PluginContext } from '@objectstack/core';
export type { Plugin, PluginContext };
export class ObjectQLPlugin implements Plugin {
name = 'com.objectstack.engine.objectql';
type = 'objectql' as const;
version = '1.0.0';
private ql: ObjectQL | undefined;
private hostContext?: Record<string, any>;
constructor(ql?: ObjectQL, hostContext?: Record<string, any>) {
if (ql) {
this.ql = ql;
} else {
this.hostContext = hostContext;
// Lazily created in init
}
}
async init(ctx: PluginContext) {
if (!this.ql) {
this.ql = new ObjectQL(this.hostContext);
}
ctx.registerService('objectql', this.ql);
ctx.logger.info('ObjectQL engine registered as service');
// Register Protocol Implementation
if (!this.ql) {
throw new Error('ObjectQL engine not initialized');
}
const protocolShim = new ObjectStackProtocolImplementation(this.ql);
ctx.registerService('protocol', protocolShim);
ctx.logger.info('Protocol service registered');
}
async start(ctx: PluginContext) {
ctx.logger.info('ObjectQL engine initialized');
// Discover features from Kernel Services
if (ctx.getServices && this.ql) {
const services = ctx.getServices();
for (const [name, service] of services.entries()) {
if (name.startsWith('driver.')) {
// Register Driver
this.ql.registerDriver(service);
ctx.logger.debug('Discovered and registered driver service', { serviceName: name });
}
if (name.startsWith('app.')) {
// Register App
this.ql.registerApp(service); // service is Manifest
ctx.logger.debug('Discovered and registered app service', { serviceName: name });
}
}
}
}
}