Skip to content

Commit 5c7c1b2

Browse files
authored
Merge pull request #373 from objectstack-ai/copilot/refactor-objectql-core
2 parents 6c431a5 + aa5d789 commit 5c7c1b2

28 files changed

Lines changed: 3319 additions & 51 deletions

packages/foundation/core/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
},
3131
"dependencies": {
3232
"@objectql/plugin-formula": "workspace:*",
33+
"@objectql/plugin-optimizations": "workspace:*",
34+
"@objectql/plugin-query": "workspace:*",
3335
"@objectql/plugin-validator": "workspace:*",
3436
"@objectql/types": "workspace:*",
3537
"@objectstack/core": "^2.0.6",

packages/foundation/core/src/index.ts

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
// Re-export types from @objectstack packages for API compatibility
9+
// ── Re-export upstream canonical engine ──
1010
export type { ObjectKernel } from '@objectstack/runtime';
1111
export type { ObjectStackProtocolImplementation } from '@objectstack/objectql';
1212

@@ -21,6 +21,15 @@ export {
2121
} from '@objectstack/objectql';
2222
export type { ObjectContributor } from '@objectstack/objectql';
2323

24+
// Re-export upstream types exported by @objectstack/objectql for plugin authors
25+
export type {
26+
ObjectQLHostContext,
27+
HookHandler as UpstreamHookHandler,
28+
HookEntry,
29+
OperationContext,
30+
EngineMiddleware,
31+
} from '@objectstack/objectql';
32+
2433
// Export ObjectStack spec types for driver development
2534
import { Data, Automation } from '@objectstack/spec';
2635
import { z } from 'zod';
@@ -33,21 +42,74 @@ export type StateMachineConfig = z.infer<typeof Automation.StateMachineSchema>;
3342
export type ObjectOwnership = z.infer<typeof Data.ObjectOwnershipEnum>;
3443
export type ObjectExtension = z.infer<typeof Data.ObjectExtensionSchema>;
3544

45+
// ── Convenience factory ──
46+
export { createObjectQLKernel, type ObjectQLKernelOptions } from './kernel-factory';
47+
48+
// ── Gateway (kept in core — upstream server handles API layer) ──
3649
export * from './gateway';
3750

38-
// Export our enhanced runtime components (actual implementations)
51+
// ── Core runtime components (backward compatibility) ──
3952
export * from './repository';
4053
export * from './app';
4154
export * from './plugin';
4255

43-
// Export query-specific modules (ObjectQL core competency)
44-
export * from './query';
45-
46-
// Export utilities
56+
// ── Utilities ──
4757
export * from './util';
4858

49-
// Export kernel optimizations
50-
export * from './optimizations';
51-
52-
// Export AI runtime
59+
// ── AI runtime (kept in core — separate AI project) ──
5360
export * from './ai';
61+
62+
// ── Re-export from @objectql/plugin-query (backward compatibility) ──
63+
// Import from '@objectql/plugin-query' directly for new code.
64+
65+
/** @deprecated Import from '@objectql/plugin-query' instead */
66+
export { QueryService } from '@objectql/plugin-query';
67+
/** @deprecated Import from '@objectql/plugin-query' instead */
68+
export { QueryBuilder } from '@objectql/plugin-query';
69+
/** @deprecated Import from '@objectql/plugin-query' instead */
70+
export { QueryAnalyzer } from '@objectql/plugin-query';
71+
/** @deprecated Import from '@objectql/plugin-query' instead */
72+
export { FilterTranslator } from '@objectql/plugin-query';
73+
/** @deprecated Import from '@objectql/plugin-query' instead */
74+
export { QueryPlugin } from '@objectql/plugin-query';
75+
76+
export type {
77+
QueryOptions,
78+
QueryResult,
79+
QueryProfile,
80+
} from '@objectql/plugin-query';
81+
export type {
82+
QueryPlan,
83+
ProfileResult,
84+
QueryStats,
85+
} from '@objectql/plugin-query';
86+
87+
// ── Re-export from @objectql/plugin-optimizations (backward compatibility) ──
88+
// Import from '@objectql/plugin-optimizations' directly for new code.
89+
90+
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
91+
export { OptimizedMetadataRegistry } from '@objectql/plugin-optimizations';
92+
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
93+
export { QueryCompiler } from '@objectql/plugin-optimizations';
94+
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
95+
export { CompiledHookManager } from '@objectql/plugin-optimizations';
96+
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
97+
export { GlobalConnectionPool } from '@objectql/plugin-optimizations';
98+
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
99+
export { OptimizedValidationEngine } from '@objectql/plugin-optimizations';
100+
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
101+
export { LazyMetadataLoader } from '@objectql/plugin-optimizations';
102+
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
103+
export { DependencyGraph } from '@objectql/plugin-optimizations';
104+
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
105+
export { SQLQueryOptimizer } from '@objectql/plugin-optimizations';
106+
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
107+
export { OptimizationsPlugin } from '@objectql/plugin-optimizations';
108+
109+
export type { CompiledQuery } from '@objectql/plugin-optimizations';
110+
export type { Hook } from '@objectql/plugin-optimizations';
111+
export type { Connection, PoolLimits } from '@objectql/plugin-optimizations';
112+
export type { ValidatorFunction, ValidationSchema } from '@objectql/plugin-optimizations';
113+
export type { ObjectMetadata, MetadataLoader } from '@objectql/plugin-optimizations';
114+
export type { DependencyEdge, DependencyType } from '@objectql/plugin-optimizations';
115+
export type { IndexMetadata, SchemaWithIndexes, OptimizableQueryAST } from '@objectql/plugin-optimizations';
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* ObjectQL Kernel Factory
3+
* Copyright (c) 2026-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
import { ObjectKernel } from '@objectstack/runtime';
10+
import { ObjectQLPlugin as UpstreamObjectQLPlugin } from '@objectstack/objectql';
11+
import type { Plugin } from '@objectstack/core';
12+
13+
/**
14+
* Options for creating an ObjectQL Kernel
15+
*/
16+
export interface ObjectQLKernelOptions {
17+
/**
18+
* Additional plugins to register with the kernel
19+
*/
20+
plugins?: Plugin[];
21+
}
22+
23+
/**
24+
* Convenience factory for creating an ObjectQL-ready kernel.
25+
*
26+
* Creates an ObjectStackKernel pre-configured with the upstream ObjectQLPlugin
27+
* (data engine, schema registry, protocol implementation) plus any additional
28+
* plugins provided.
29+
*
30+
* @example
31+
* ```typescript
32+
* import { createObjectQLKernel } from '@objectql/core';
33+
* import { QueryPlugin } from '@objectql/plugin-query';
34+
* import { OptimizationsPlugin } from '@objectql/plugin-optimizations';
35+
*
36+
* const kernel = createObjectQLKernel({
37+
* plugins: [new QueryPlugin(), new OptimizationsPlugin()],
38+
* });
39+
* await kernel.start();
40+
* ```
41+
*/
42+
export function createObjectQLKernel(options: ObjectQLKernelOptions = {}): ObjectKernel {
43+
return new (ObjectKernel as any)([
44+
new UpstreamObjectQLPlugin(),
45+
...(options.plugins || []),
46+
]);
47+
}

packages/foundation/core/src/plugin.ts

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,12 @@ import { ConsoleLogger, ObjectQLError } from '@objectql/types';
1111
import type { Logger } from '@objectql/types';
1212
import { ValidatorPlugin, ValidatorPluginConfig } from '@objectql/plugin-validator';
1313
import { FormulaPlugin, FormulaPluginConfig } from '@objectql/plugin-formula';
14-
import { QueryService } from './query/query-service';
15-
import { QueryAnalyzer } from './query/query-analyzer';
14+
import { QueryPlugin } from '@objectql/plugin-query';
1615
import { ObjectStackProtocolImplementation } from './protocol';
1716
import type { Driver } from '@objectql/types';
1817
import { createDefaultAiRegistry } from './ai';
1918
import { SchemaRegistry } from '@objectstack/objectql';
2019

21-
/**
22-
* Extended kernel with ObjectQL services
23-
*/
24-
interface ExtendedKernel {
25-
metadata?: any;
26-
actions?: any;
27-
hooks?: any;
28-
getAllDrivers?: () => Driver[];
29-
create?: (objectName: string, data: any) => Promise<any>;
30-
update?: (objectName: string, id: string, data: any) => Promise<any>;
31-
delete?: (objectName: string, id: string) => Promise<any>;
32-
find?: (objectName: string, query: any) => Promise<any>;
33-
get?: (objectName: string, id: string) => Promise<any>;
34-
queryService?: QueryService;
35-
queryAnalyzer?: QueryAnalyzer;
36-
}
37-
3820
/**
3921
* Configuration for the ObjectQL Plugin
4022
*/
@@ -91,12 +73,15 @@ export interface ObjectQLPluginConfig {
9173
/**
9274
* ObjectQL Plugin
9375
*
94-
* Implements the RuntimePlugin interface to provide ObjectQL's enhanced features
95-
* (Repository, Validator, Formula, AI) on top of the microkernel.
76+
* Thin orchestrator that composes ObjectQL's extension plugins
77+
* (QueryPlugin, ValidatorPlugin, FormulaPlugin, AI) on top of the microkernel.
78+
*
79+
* Delegates query execution to @objectql/plugin-query and provides
80+
* repository-pattern CRUD bridging to the kernel.
9681
*/
9782
export class ObjectQLPlugin implements RuntimePlugin {
9883
name = '@objectql/core';
99-
version = '4.0.2';
84+
version = '4.2.0';
10085
private logger: Logger;
10186

10287
constructor(private config: ObjectQLPluginConfig = {}, _ql?: any) {
@@ -119,7 +104,7 @@ export class ObjectQLPlugin implements RuntimePlugin {
119104
async install(ctx: RuntimeContext): Promise<void> {
120105
this.logger.info('Installing plugin...');
121106

122-
const kernel = ctx.engine as ExtendedKernel;
107+
const kernel = ctx.engine as any;
123108

124109
// Get datasources - either from config or from kernel drivers
125110
let datasources = this.config.datasources;
@@ -141,21 +126,11 @@ export class ObjectQLPlugin implements RuntimePlugin {
141126
}
142127
}
143128

144-
// Register QueryService and QueryAnalyzer if enabled
129+
// Delegate query service registration to QueryPlugin
145130
if (this.config.enableQueryService !== false && datasources) {
146-
const queryService = new QueryService(
147-
datasources,
148-
kernel.metadata
149-
);
150-
kernel.queryService = queryService;
151-
152-
const queryAnalyzer = new QueryAnalyzer(
153-
queryService,
154-
kernel.metadata
155-
);
156-
kernel.queryAnalyzer = queryAnalyzer;
157-
158-
this.logger.info('QueryService and QueryAnalyzer registered');
131+
const queryPlugin = new QueryPlugin({ datasources });
132+
await queryPlugin.install(ctx);
133+
this.logger.info('QueryPlugin installed (QueryService + QueryAnalyzer)');
159134
}
160135

161136
// Register components based on configuration
@@ -280,8 +255,6 @@ export class ObjectQLPlugin implements RuntimePlugin {
280255
kernel.count = async (objectName: string, filters?: any): Promise<number> => {
281256
// Use QueryService if available
282257
if ((kernel as any).queryService) {
283-
// QueryService.count expects a UnifiedQuery filter or just filter object?
284-
// Looking at QueryService.count signature: count(objectName: string, where?: Filter, options?: QueryOptions)
285258
const result = await (kernel as any).queryService.count(objectName, filters);
286259
return result.value;
287260
}

packages/foundation/core/test/plugin-integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('ObjectQLPlugin Integration', () => {
4646
it('should have correct name and version', () => {
4747
plugin = new ObjectQLPlugin();
4848
expect(plugin.name).toBe('@objectql/core');
49-
expect(plugin.version).toBe('4.0.2');
49+
expect(plugin.version).toBe('4.2.0');
5050
});
5151
});
5252

packages/foundation/core/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"references": [
1313
{ "path": "../types" },
1414
{ "path": "../plugin-validator" },
15-
{ "path": "../plugin-formula" }
15+
{ "path": "../plugin-formula" },
16+
{ "path": "../plugin-query" },
17+
{ "path": "../plugin-optimizations" }
1618
]
1719
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@objectql/plugin-optimizations",
3+
"version": "4.2.0",
4+
"description": "Performance optimization plugins for ObjectQL - connection pooling, LRU cache, compiled hooks",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"sideEffects": false,
8+
"exports": {
9+
".": {
10+
"types": "./dist/index.d.ts",
11+
"default": "./dist/index.js"
12+
}
13+
},
14+
"files": ["dist"],
15+
"scripts": {
16+
"build": "tsc",
17+
"test": "vitest run"
18+
},
19+
"dependencies": {
20+
"@objectql/types": "workspace:*",
21+
"@objectstack/core": "^2.0.6",
22+
"@objectstack/spec": "^2.0.6"
23+
},
24+
"devDependencies": {
25+
"typescript": "^5.3.0"
26+
}
27+
}

0 commit comments

Comments
 (0)