Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/foundation/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
},
"dependencies": {
"@objectql/plugin-formula": "workspace:*",
"@objectql/plugin-optimizations": "workspace:*",
"@objectql/plugin-query": "workspace:*",
"@objectql/plugin-validator": "workspace:*",
"@objectql/types": "workspace:*",
"@objectstack/core": "^2.0.6",
Expand Down
82 changes: 72 additions & 10 deletions packages/foundation/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

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

Expand All @@ -21,6 +21,15 @@ export {
} from '@objectstack/objectql';
export type { ObjectContributor } from '@objectstack/objectql';

// Re-export upstream types exported by @objectstack/objectql for plugin authors
export type {
ObjectQLHostContext,
HookHandler as UpstreamHookHandler,
HookEntry,
OperationContext,
EngineMiddleware,
} from '@objectstack/objectql';

// Export ObjectStack spec types for driver development
import { Data, Automation } from '@objectstack/spec';
import { z } from 'zod';
Expand All @@ -33,21 +42,74 @@ export type StateMachineConfig = z.infer<typeof Automation.StateMachineSchema>;
export type ObjectOwnership = z.infer<typeof Data.ObjectOwnershipEnum>;
export type ObjectExtension = z.infer<typeof Data.ObjectExtensionSchema>;

// ── Convenience factory ──
export { createObjectQLKernel, type ObjectQLKernelOptions } from './kernel-factory';

// ── Gateway (kept in core — upstream server handles API layer) ──
export * from './gateway';

// Export our enhanced runtime components (actual implementations)
// ── Core runtime components (backward compatibility) ──
export * from './repository';
export * from './app';
export * from './plugin';

// Export query-specific modules (ObjectQL core competency)
export * from './query';

// Export utilities
// ── Utilities ──
export * from './util';

// Export kernel optimizations
export * from './optimizations';

// Export AI runtime
// ── AI runtime (kept in core — separate AI project) ──
export * from './ai';

// ── Re-export from @objectql/plugin-query (backward compatibility) ──
// Import from '@objectql/plugin-query' directly for new code.

/** @deprecated Import from '@objectql/plugin-query' instead */
export { QueryService } from '@objectql/plugin-query';
/** @deprecated Import from '@objectql/plugin-query' instead */
export { QueryBuilder } from '@objectql/plugin-query';
/** @deprecated Import from '@objectql/plugin-query' instead */
export { QueryAnalyzer } from '@objectql/plugin-query';
/** @deprecated Import from '@objectql/plugin-query' instead */
export { FilterTranslator } from '@objectql/plugin-query';
/** @deprecated Import from '@objectql/plugin-query' instead */
export { QueryPlugin } from '@objectql/plugin-query';

export type {
QueryOptions,
QueryResult,
QueryProfile,
} from '@objectql/plugin-query';
export type {
QueryPlan,
ProfileResult,
QueryStats,
} from '@objectql/plugin-query';

// ── Re-export from @objectql/plugin-optimizations (backward compatibility) ──
// Import from '@objectql/plugin-optimizations' directly for new code.

/** @deprecated Import from '@objectql/plugin-optimizations' instead */
export { OptimizedMetadataRegistry } from '@objectql/plugin-optimizations';
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
export { QueryCompiler } from '@objectql/plugin-optimizations';
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
export { CompiledHookManager } from '@objectql/plugin-optimizations';
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
export { GlobalConnectionPool } from '@objectql/plugin-optimizations';
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
export { OptimizedValidationEngine } from '@objectql/plugin-optimizations';
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
export { LazyMetadataLoader } from '@objectql/plugin-optimizations';
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
export { DependencyGraph } from '@objectql/plugin-optimizations';
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
export { SQLQueryOptimizer } from '@objectql/plugin-optimizations';
/** @deprecated Import from '@objectql/plugin-optimizations' instead */
export { OptimizationsPlugin } from '@objectql/plugin-optimizations';

export type { CompiledQuery } from '@objectql/plugin-optimizations';
export type { Hook } from '@objectql/plugin-optimizations';
export type { Connection, PoolLimits } from '@objectql/plugin-optimizations';
export type { ValidatorFunction, ValidationSchema } from '@objectql/plugin-optimizations';
export type { ObjectMetadata, MetadataLoader } from '@objectql/plugin-optimizations';
export type { DependencyEdge, DependencyType } from '@objectql/plugin-optimizations';
export type { IndexMetadata, SchemaWithIndexes, OptimizableQueryAST } from '@objectql/plugin-optimizations';
47 changes: 47 additions & 0 deletions packages/foundation/core/src/kernel-factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* ObjectQL Kernel Factory
* Copyright (c) 2026-present ObjectStack Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import { ObjectKernel } from '@objectstack/runtime';
import { ObjectQLPlugin as UpstreamObjectQLPlugin } from '@objectstack/objectql';
import type { Plugin } from '@objectstack/core';

Comment on lines +9 to +12
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plugin is imported from @objectstack/core here, but elsewhere (e.g. app.ts) Plugin is imported from @objectstack/runtime alongside ObjectKernel. Using different Plugin types can create assignability issues for options.plugins. Import Plugin from the same package as ObjectKernel (or use a shared upstream type) to keep the factory’s API consistent.

Suggested change
import { ObjectKernel } from '@objectstack/runtime';
import { ObjectQLPlugin as UpstreamObjectQLPlugin } from '@objectstack/objectql';
import type { Plugin } from '@objectstack/core';
import { ObjectKernel, type Plugin } from '@objectstack/runtime';
import { ObjectQLPlugin as UpstreamObjectQLPlugin } from '@objectstack/objectql';

Copilot uses AI. Check for mistakes.
/**
* Options for creating an ObjectQL Kernel
*/
export interface ObjectQLKernelOptions {
/**
* Additional plugins to register with the kernel
*/
plugins?: Plugin[];
}

/**
* Convenience factory for creating an ObjectQL-ready kernel.
*
* Creates an ObjectStackKernel pre-configured with the upstream ObjectQLPlugin
* (data engine, schema registry, protocol implementation) plus any additional
* plugins provided.
*
* @example
* ```typescript
* import { createObjectQLKernel } from '@objectql/core';
* import { QueryPlugin } from '@objectql/plugin-query';
* import { OptimizationsPlugin } from '@objectql/plugin-optimizations';
*
* const kernel = createObjectQLKernel({
* plugins: [new QueryPlugin(), new OptimizationsPlugin()],
* });
* await kernel.start();
* ```
*/
export function createObjectQLKernel(options: ObjectQLKernelOptions = {}): ObjectKernel {
return new (ObjectKernel as any)([
new UpstreamObjectQLPlugin(),
...(options.plugins || []),
]);
}
51 changes: 12 additions & 39 deletions packages/foundation/core/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,12 @@ import { ConsoleLogger, ObjectQLError } from '@objectql/types';
import type { Logger } from '@objectql/types';
import { ValidatorPlugin, ValidatorPluginConfig } from '@objectql/plugin-validator';
import { FormulaPlugin, FormulaPluginConfig } from '@objectql/plugin-formula';
import { QueryService } from './query/query-service';
import { QueryAnalyzer } from './query/query-analyzer';
import { QueryPlugin } from '@objectql/plugin-query';
import { ObjectStackProtocolImplementation } from './protocol';
import type { Driver } from '@objectql/types';
import { createDefaultAiRegistry } from './ai';
import { SchemaRegistry } from '@objectstack/objectql';

/**
* Extended kernel with ObjectQL services
*/
interface ExtendedKernel {
metadata?: any;
actions?: any;
hooks?: any;
getAllDrivers?: () => Driver[];
create?: (objectName: string, data: any) => Promise<any>;
update?: (objectName: string, id: string, data: any) => Promise<any>;
delete?: (objectName: string, id: string) => Promise<any>;
find?: (objectName: string, query: any) => Promise<any>;
get?: (objectName: string, id: string) => Promise<any>;
queryService?: QueryService;
queryAnalyzer?: QueryAnalyzer;
}

/**
* Configuration for the ObjectQL Plugin
*/
Expand Down Expand Up @@ -91,12 +73,15 @@ export interface ObjectQLPluginConfig {
/**
* ObjectQL Plugin
*
* Implements the RuntimePlugin interface to provide ObjectQL's enhanced features
* (Repository, Validator, Formula, AI) on top of the microkernel.
* Thin orchestrator that composes ObjectQL's extension plugins
* (QueryPlugin, ValidatorPlugin, FormulaPlugin, AI) on top of the microkernel.
*
* Delegates query execution to @objectql/plugin-query and provides
* repository-pattern CRUD bridging to the kernel.
*/
export class ObjectQLPlugin implements RuntimePlugin {
name = '@objectql/core';
version = '4.0.2';
version = '4.2.0';
private logger: Logger;

constructor(private config: ObjectQLPluginConfig = {}, _ql?: any) {
Comment on lines 86 to 87
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This write to property 'config' is useless, since another property write always overrides it.

Suggested change
constructor(private config: ObjectQLPluginConfig = {}, _ql?: any) {
private config: ObjectQLPluginConfig;
constructor(config: ObjectQLPluginConfig = {}, _ql?: any) {

Copilot uses AI. Check for mistakes.
Expand All @@ -119,7 +104,7 @@ export class ObjectQLPlugin implements RuntimePlugin {
async install(ctx: RuntimeContext): Promise<void> {
this.logger.info('Installing plugin...');

const kernel = ctx.engine as ExtendedKernel;
const kernel = ctx.engine as any;

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

// Register QueryService and QueryAnalyzer if enabled
// Delegate query service registration to QueryPlugin
if (this.config.enableQueryService !== false && datasources) {
const queryService = new QueryService(
datasources,
kernel.metadata
);
kernel.queryService = queryService;

const queryAnalyzer = new QueryAnalyzer(
queryService,
kernel.metadata
);
kernel.queryAnalyzer = queryAnalyzer;

this.logger.info('QueryService and QueryAnalyzer registered');
const queryPlugin = new QueryPlugin({ datasources });
await queryPlugin.install(ctx);
this.logger.info('QueryPlugin installed (QueryService + QueryAnalyzer)');
}

// Register components based on configuration
Expand Down Expand Up @@ -280,8 +255,6 @@ export class ObjectQLPlugin implements RuntimePlugin {
kernel.count = async (objectName: string, filters?: any): Promise<number> => {
// Use QueryService if available
if ((kernel as any).queryService) {
// QueryService.count expects a UnifiedQuery filter or just filter object?
// Looking at QueryService.count signature: count(objectName: string, where?: Filter, options?: QueryOptions)
const result = await (kernel as any).queryService.count(objectName, filters);
return result.value;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/foundation/core/test/plugin-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('ObjectQLPlugin Integration', () => {
it('should have correct name and version', () => {
plugin = new ObjectQLPlugin();
expect(plugin.name).toBe('@objectql/core');
expect(plugin.version).toBe('4.0.2');
expect(plugin.version).toBe('4.2.0');
});
});

Expand Down
4 changes: 3 additions & 1 deletion packages/foundation/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"references": [
{ "path": "../types" },
{ "path": "../plugin-validator" },
{ "path": "../plugin-formula" }
{ "path": "../plugin-formula" },
{ "path": "../plugin-query" },
{ "path": "../plugin-optimizations" }
]
}
27 changes: 27 additions & 0 deletions packages/foundation/plugin-optimizations/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@objectql/plugin-optimizations",
"version": "4.2.0",
"description": "Performance optimization plugins for ObjectQL - connection pooling, LRU cache, compiled hooks",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"files": ["dist"],
"scripts": {
"build": "tsc",
"test": "vitest run"
},
"dependencies": {
"@objectql/types": "workspace:*",
"@objectstack/core": "^2.0.6",
"@objectstack/spec": "^2.0.6"
},
"devDependencies": {
"typescript": "^5.3.0"
}
}
Loading