-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobjectql-plugin.ts
More file actions
80 lines (70 loc) · 2.29 KB
/
objectql-plugin.ts
File metadata and controls
80 lines (70 loc) · 2.29 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { ObjectQL } from '@objectstack/objectql';
import { Plugin, PluginContext } from './types.js';
/**
* ObjectQL Engine Plugin
*
* Registers the ObjectQL engine instance with the kernel as a service.
* This allows other plugins to access ObjectQL via context.getService('objectql').
*
* Usage:
* - new ObjectQLPlugin() - Creates new ObjectQL with default settings
* - new ObjectQLPlugin(existingQL) - Uses existing ObjectQL instance
* - new ObjectQLPlugin(undefined, { custom: 'context' }) - Creates new ObjectQL with custom context
*
* Services registered:
* - 'objectql': ObjectQL engine instance
*/
export class ObjectQLPlugin implements Plugin {
name = 'com.objectstack.engine.objectql';
type = 'objectql' as const;
version = '1.0.0';
private ql: ObjectQL;
/**
* @param ql - Existing ObjectQL instance to use (optional)
* @param hostContext - Host context for new ObjectQL instance (ignored if ql is provided)
*/
constructor(ql?: ObjectQL, hostContext?: Record<string, any>) {
if (ql && hostContext) {
console.warn('[ObjectQLPlugin] Both ql and hostContext provided. hostContext will be ignored.');
}
if (ql) {
this.ql = ql;
} else {
this.ql = new ObjectQL(hostContext || {
env: process.env.NODE_ENV || 'development'
});
}
}
/**
* Init phase - Register ObjectQL as a service
*/
async init(ctx: PluginContext) {
// Register ObjectQL engine as 'objectql' service (legacy name)
ctx.registerService('objectql', this.ql);
// Register ObjectQL engine as 'data-engine' service (IDataEngine interface)
ctx.registerService('data-engine', this.ql);
ctx.logger.log('[ObjectQLPlugin] ObjectQL engine registered as services: objectql, data-engine');
}
/**
* Start phase - Initialize ObjectQL engine
*/
async start(ctx: PluginContext) {
// Initialize the ObjectQL engine
await this.ql.init();
ctx.logger.log('[ObjectQLPlugin] ObjectQL engine initialized');
}
/**
* Destroy phase - Cleanup
*/
async destroy() {
// ObjectQL doesn't have cleanup yet, but we provide the hook
console.log('[ObjectQLPlugin] ObjectQL engine destroyed');
}
/**
* Get the ObjectQL instance
* @returns ObjectQL instance
*/
getQL(): ObjectQL {
return this.ql;
}
}