Skip to content

Commit d488619

Browse files
Copilothotlong
andcommitted
refactor: Use type-based detection for ObjectQL plugin instead of symbol
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 536f086 commit d488619

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

OBJECTQL_PLUGIN_QUICKSTART.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,17 @@ new ObjectQLPlugin(undefined, { env: 'prod' }) // Create with context
186186

187187
## Advanced
188188

189-
### Symbol-Based Detection
189+
### Type-Based Detection
190190

191-
ObjectQLPlugin uses a symbol for reliable detection:
191+
ObjectQLPlugin uses a `type` field for reliable detection:
192192

193193
```typescript
194-
import { OBJECTQL_PLUGIN_MARKER } from '@objectstack/runtime';
195-
196194
// Check if a plugin is an ObjectQL plugin
197-
const isObjectQLPlugin = OBJECTQL_PLUGIN_MARKER in plugin;
195+
const isObjectQLPlugin = plugin && plugin.type === 'objectql';
198196
```
199197

198+
The plugin sets `type = 'objectql'` which aligns with the manifest schema that supports package types: 'app', 'plugin', 'driver', 'module', 'objectql', 'gateway', 'adapter'.
199+
200200
### Type Safety
201201

202202
The kernel's `ql` property is typed as optional:

packages/runtime/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Export core engine
22
export { ObjectQL, SchemaRegistry } from '@objectstack/objectql';
33
export { ObjectStackKernel } from './kernel';
4-
export { ObjectQLPlugin, OBJECTQL_PLUGIN_MARKER } from './objectql-plugin';
4+
export { ObjectQLPlugin } from './objectql-plugin';
55
export { ObjectStackRuntimeProtocol } from './protocol';
66

77
export * from './types';

packages/runtime/src/kernel.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ServiceObject } from '@objectstack/spec/data';
22
import { SchemaRegistry, ObjectQL } from '@objectstack/objectql';
3-
import { OBJECTQL_PLUGIN_MARKER } from './objectql-plugin';
43

54
/**
65
* ObjectStack Kernel (Microkernel)
@@ -15,10 +14,10 @@ export class ObjectStackKernel {
1514
constructor(plugins: any[] = []) {
1615
this.plugins = plugins;
1716

18-
// Check if any plugin provides ObjectQL via the plugin marker
19-
// This is more robust than string matching on name
17+
// Check if any plugin provides ObjectQL via type: 'objectql'
18+
// This aligns with the manifest schema that supports objectql as a package type
2019
const hasObjectQLPlugin = plugins.some(p =>
21-
p && typeof p === 'object' && OBJECTQL_PLUGIN_MARKER in p
20+
p && typeof p === 'object' && p.type === 'objectql'
2221
);
2322

2423
if (!hasObjectQLPlugin) {

packages/runtime/src/objectql-plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const OBJECTQL_PLUGIN_MARKER = Symbol('objectql-plugin');
1919
*/
2020
export class ObjectQLPlugin implements RuntimePlugin {
2121
name = 'com.objectstack.engine.objectql';
22+
type = 'objectql' as const;
2223

2324
// Mark this as an ObjectQL plugin for reliable detection
2425
readonly [OBJECTQL_PLUGIN_MARKER] = true;

0 commit comments

Comments
 (0)